lmt commited on
Commit
f00d827
·
1 Parent(s): 566ac72

post接口支持上下文

Browse files
Files changed (1) hide show
  1. main.py +10 -4
main.py CHANGED
@@ -131,14 +131,17 @@ async def websocket_endpoint(websocket: WebSocket):
131
 
132
  class Item(BaseModel):
133
  _msgid: Union[str, None] = None
134
- input: str
135
  history: List[Dict] = []
136
 
137
 
138
  @app.post("/api/chat")
139
  def chat(item: Item):
140
  print(item)
141
- history = [construct_user(item.input)]
 
 
 
142
  res = get_response(initial_prompt, history)
143
  return res
144
 
@@ -149,11 +152,14 @@ initial_prompt = "You are a helpful assistant."
149
 
150
  def get_response(system_prompt, history):
151
 
152
- history = [construct_system(system_prompt), *history]
 
 
 
153
 
154
  payload = {
155
  "model": "gpt-3.5-turbo",
156
- "messages": history, # [{"role": "user", "content": f"{inputs}"}],
157
  }
158
 
159
  print(f"payload: -->{payload}")
 
131
 
132
  class Item(BaseModel):
133
  _msgid: Union[str, None] = None
134
+ input: str = ""
135
  history: List[Dict] = []
136
 
137
 
138
  @app.post("/api/chat")
139
  def chat(item: Item):
140
  print(item)
141
+ history = [*item.history]
142
+
143
+ if item.input:
144
+ history.append({"role": "user", "content": f"{item.input}"})
145
  res = get_response(initial_prompt, history)
146
  return res
147
 
 
152
 
153
  def get_response(system_prompt, history):
154
 
155
+ messages = [
156
+ {"role": "system", "content": f"{system_prompt}"},
157
+ *history
158
+ ]
159
 
160
  payload = {
161
  "model": "gpt-3.5-turbo",
162
+ "messages": messages,
163
  }
164
 
165
  print(f"payload: -->{payload}")