Spaces:
Running
Running
Update ChatResponse.py
Browse files- ChatResponse.py +20 -2
ChatResponse.py
CHANGED
@@ -6,13 +6,31 @@ openai.api_key = os.environ["OPENAI_API_KEY"]
|
|
6 |
# ChatGPT completion
|
7 |
llm_name = "gpt-3.5-turbo"
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
def get_completion_from_messages(messages, model=llm_name, temperature=0):
|
10 |
-
response = openai.
|
11 |
model=model,
|
12 |
messages=messages,
|
13 |
temperature=temperature, # this is the degree of randomness of the model's output
|
|
|
|
|
14 |
)
|
15 |
-
return response.choices[0]
|
16 |
|
17 |
def template(context):
|
18 |
text=f"""Responde a la entrada previa del usuario, usando el siguiente \
|
|
|
6 |
# ChatGPT completion
|
7 |
llm_name = "gpt-3.5-turbo"
|
8 |
|
9 |
+
# Función para tomar pedido del usuario
|
10 |
+
tools = [{
|
11 |
+
"type": "function",
|
12 |
+
"function":{
|
13 |
+
"name": "enviar_pedido",
|
14 |
+
"description": "construye y envía el pedido hecho en la conversación, si éste ha finalizado y el usuario no desea llevar más artículos",
|
15 |
+
"parameters": {
|
16 |
+
"type": "object",
|
17 |
+
"properties": {"final": {"type": "string",
|
18 |
+
"enum": ["S"],
|
19 |
+
"description":"determina si el pedido del usuario ha terminado"}},
|
20 |
+
"required": ["final"]
|
21 |
+
}
|
22 |
+
}
|
23 |
+
}]
|
24 |
+
|
25 |
def get_completion_from_messages(messages, model=llm_name, temperature=0):
|
26 |
+
response = openai.chat.completions.create(
|
27 |
model=model,
|
28 |
messages=messages,
|
29 |
temperature=temperature, # this is the degree of randomness of the model's output
|
30 |
+
tools=tools,
|
31 |
+
tool_choice="auto"
|
32 |
)
|
33 |
+
return response.choices[0]
|
34 |
|
35 |
def template(context):
|
36 |
text=f"""Responde a la entrada previa del usuario, usando el siguiente \
|