-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py.bak
More file actions
68 lines (51 loc) · 2.49 KB
/
main.py.bak
File metadata and controls
68 lines (51 loc) · 2.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import os
from dotenv import load_dotenv
from openai import OpenAI
from pypdf import PdfReader
import gradio as gr
def main():
load_dotenv(override=True)
openai_api_key = os.getenv('OPENAI_API_KEY')
anthropic_api_key = os.getenv('ANTHROPIC_API_KEY')
deepseek_api_key = os.getenv('DEEPSEEK_API_KEY')
# openai = OpenAI()
deepseek = OpenAI(api_key=deepseek_api_key, base_url="https://api.deepseek.com/v1")
if openai_api_key:
print(f"OpenAI API Key exists and begins {openai_api_key[:8]}")
else:
print("OpenAI API Key not set")
if anthropic_api_key:
print(f"Anthropic API Key exists and begins {anthropic_api_key[:7]}")
else:
print("Anthropic API Key not set (and this is optional)")
if deepseek_api_key:
print(f"DeepSeek API Key exists and begins {deepseek_api_key[:3]}")
else:
print("DeepSeek API Key not set (and this is optional)")
print("Hello from gradio!")
reader = PdfReader("linkedin.pdf")
linkedin = ""
for page in reader.pages:
text = page.extract_text()
if text:
linkedin += text
# print(linkedin)
with open("summary.txt", "r", encoding="utf-8") as f:
summary = f.read()
name = "Jordan Phillips"
system_prompt = f"You are acting as {name}. You are answering questions on {name}'s website, \
particularly questions related to {name}'s career, background, skills and experience. \
Your responsibility is to represent {name} for interactions on the website as faithfully as possible. \
You are given a summary of {name}'s background and LinkedIn profile which you can use to answer questions. \
Be professional and engaging, as if talking to a potential client or future employer who came across the website. \
If you don't know the answer, say so."
system_prompt += f"\n\n## Summary:\n{summary}\n\n## LinkedIn Profile:\n{linkedin}\n\n"
system_prompt += f"With this context, please chat with the user, always staying in character as {name}."
def chat(message, history):
messages = [{"role": "system", "content": system_prompt}] + history + [{"role": "user", "content": message}]
#response = openai.chat.completions.create(model="gpt-4o-mini", messages=messages)
response = deepseek.chat.completions.create(model="deepseek-chat", messages=messages)
return response.choices[0].message.content
gr.ChatInterface(chat, type="messages").launch()
if __name__ == "__main__":
main()