ranranrunforit commited on
Commit
41c5912
·
verified ·
1 Parent(s): 04d1036

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -24
app.py CHANGED
@@ -76,15 +76,14 @@ tools = [{"type": "function", "function": record_user_details_json},
76
  class Me:
77
 
78
  def __init__(self):
79
- open_router_api_key = os.getenv('OPEN_ROUTER_API_KEY')
80
- if open_router_api_key:
81
- print(f"Open router API Key exists and begins {open_router_api_key[:8]}")
82
- else:
83
- print("Open router API Key not set - please head to the troubleshooting guide in the setup folder")
84
  self.client = OpenAI(
85
  base_url="https://openrouter.ai/api/v1",
86
- api_key=open_router_api_key
87
- )
88
  self.name = "Chaoran Zhou"
89
  reader = PdfReader("me/linkedin.pdf")
90
  self.linkedin = ""
@@ -124,23 +123,33 @@ If the user is engaging in discussion, try to steer them towards getting in touc
124
  messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
125
  done = False
126
  while not done:
127
- try:
128
- response = self.client.chat.completions.create(
129
- model="meta-llama/llama-3.3-8b-instruct:free",
130
- messages=messages,
131
- tools=tools
132
- )
133
- if response.choices[0].finish_reason == "tool_calls":
134
- message = response.choices[0].message
135
- tool_calls = message.tool_calls
136
- results = self.handle_tool_call(tool_calls)
137
- messages.append(message)
138
- messages.extend(results)
139
- else:
140
- done = True
141
- except Exception as e:
142
- print(f"Error during OpenAI API call: {e}")
143
- return "Sorry, there was an error processing your request. Please check your API key and try again."
 
 
 
 
 
 
 
 
 
 
144
 
145
  return response.choices[0].message.content
146
 
 
76
  class Me:
77
 
78
  def __init__(self):
79
+ # open_router_api_key = os.getenv('OPEN_ROUTER_API_KEY')
80
+ # if open_router_api_key:
81
+ # print(f"Checking Keys: Open router API Key exists and begins {open_router_api_key[:8]}")
82
+ # else:
83
+ # print("Checking Keys: Open router API Key not set - please head to the troubleshooting guide in the setup folder")
84
  self.client = OpenAI(
85
  base_url="https://openrouter.ai/api/v1",
86
+ api_key= os.getenv('OPEN_ROUTER_API_KEY') ) # open_router_api_key
 
87
  self.name = "Chaoran Zhou"
88
  reader = PdfReader("me/linkedin.pdf")
89
  self.linkedin = ""
 
123
  messages = [{"role": "system", "content": self.system_prompt()}] + history + [{"role": "user", "content": message}]
124
  done = False
125
  while not done:
126
+ response = self.openai.chat.completions.create(model="meta-llama/llama-3.3-8b-instruct:free", messages=messages, tools=tools)
127
+ if response.choices[0].finish_reason=="tool_calls":
128
+ message = response.choices[0].message
129
+ tool_calls = message.tool_calls
130
+ results = self.handle_tool_call(tool_calls)
131
+ messages.append(message)
132
+ messages.extend(results)
133
+ else:
134
+ done = True
135
+
136
+ # try:
137
+ # response = self.client.chat.completions.create(
138
+ # model="meta-llama/llama-3.3-8b-instruct:free",
139
+ # messages=messages,
140
+ # tools=tools
141
+ # )
142
+ # if response.choices[0].finish_reason == "tool_calls":
143
+ # message = response.choices[0].message
144
+ # tool_calls = message.tool_calls
145
+ # results = self.handle_tool_call(tool_calls)
146
+ # messages.append(message)
147
+ # messages.extend(results)
148
+ # else:
149
+ # done = True
150
+ # except Exception as e:
151
+ # print(f"Error during OpenAI API call: {e}")
152
+ # return "Sorry, there was an error processing your request. Please check your API key and try again."
153
 
154
  return response.choices[0].message.content
155