|
@@ -97,21 +97,11 @@ def fetch_moon_shot_response(task, input_text, output_type="text"):
|
|
|
base_url=moon_shot['base_url']
|
|
|
)
|
|
|
|
|
|
- # get response
|
|
|
+ # get response format
|
|
|
if output_type == "json":
|
|
|
- chat_completion = client.chat.completions.create(
|
|
|
- messages=[
|
|
|
- {
|
|
|
- "role": "user",
|
|
|
- "content": prompt,
|
|
|
- }
|
|
|
- ],
|
|
|
- model=moon_shot['model'],
|
|
|
- response_format={"type": "json_object"}
|
|
|
- )
|
|
|
- response = chat_completion.choices[0].message.content
|
|
|
- response_json = json.loads(response)
|
|
|
- return response_json
|
|
|
+ response_format = {"type": "json_object"}
|
|
|
+ else:
|
|
|
+ response_format = {"type": "text"}
|
|
|
|
|
|
chat_completion = client.chat.completions.create(
|
|
|
messages=[
|
|
@@ -120,7 +110,12 @@ def fetch_moon_shot_response(task, input_text, output_type="text"):
|
|
|
"content": prompt,
|
|
|
}
|
|
|
],
|
|
|
- model=moon_shot['model']
|
|
|
+ model=moon_shot['model'],
|
|
|
+ response_format=response_format,
|
|
|
)
|
|
|
response = chat_completion.choices[0].message.content
|
|
|
- return response
|
|
|
+ if output_type == "json":
|
|
|
+ response_json = json.loads(response)
|
|
|
+ return response_json
|
|
|
+
|
|
|
+ return response
|