Skip to content

Commit

Permalink
Merge branch '143-feature-request-add-formatting-option-to-response_f…
Browse files Browse the repository at this point in the history
…ormat' of github.com:ag2ai/ag2 into 143-feature-request-add-formatting-option-to-response_format
  • Loading branch information
sternakt committed Dec 5, 2024
2 parents c40da67 + e69118e commit a67ad8e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 0 additions & 2 deletions autogen/oai/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,6 @@ def _create_or_parse(*args, **kwargs):
params["stream"] = False
response = create_or_parse(**params)

print("!" * 100)
print(response)
return response

def cost(self, response: Union[ChatCompletion, Completion]) -> float:
Expand Down
22 changes: 11 additions & 11 deletions notebook/agentchat_structured_outputs.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
"source": [
"# Structured output\n",
"\n",
"OpenAI offers a functionality for defining a structure of the messages generated by LLMs, AutoGen enables this functionality by propagating `response_format` passed to your agents to the underlying client.\n",
"OpenAI offers functionality for defining a structure of the messages generated by LLMs, AG2 enables this functionality by propagating `response_format` passed to your agents to the underlying client.\n",
"\n",
"For more info on structured output, please check [here](https://platform.openai.com/docs/guides/structured-outputs)\n",
"\n",
"\n",
"````{=mdx}\n",
":::info Requirements\n",
"Install `pyautogen`:\n",
"Install `ag2`:\n",
"```bash\n",
"pip install pyautogen\n",
"pip install ag2\n",
"```\n",
"\n",
"For more information, please refer to the [installation guide](/docs/installation/).\n",
Expand All @@ -31,7 +31,7 @@
"source": [
"## Set your API Endpoint\n",
"\n",
"The [`config_list_from_json`](https://ag2ai.github.io/ag2/docs/reference/oai/openai_utils#config_list_from_json) function loads a list of configurations from an environment variable or a json file."
"The [`config_list_from_json`](https://ag2ai.github.io/ag2/docs/reference/oai/openai_utils#config_list_from_json) function loads a list of configurations from an environment variable or a json file. Structured Output is supported by OpenAI's models from gpt-4-0613 and gpt-3.5-turbo-0613."
]
},
{
Expand Down Expand Up @@ -77,7 +77,7 @@
"source": [
"## Example: math reasoning\n",
"\n",
"Using structured output, we can enforce chain-of-thought reasoning in the model to output an answer in a structured, step-by-step way"
"Using structured output, we can enforce chain-of-thought reasoning in the model to output an answer in a structured, step-by-step way."
]
},
{
Expand All @@ -86,7 +86,7 @@
"source": [
"### Define the reasoning model\n",
"\n",
"First we will define the math reasoning model. This model will indirectly force the LLM to solve the posed math problems iteratively trough math reasoning steps."
"First we will define the math reasoning model. This model will indirectly force the LLM to solve the posed math problems iteratively through math reasoning steps."
]
},
{
Expand Down Expand Up @@ -194,7 +194,7 @@
"source": [
"## Formatting a response\n",
"\n",
"When defining a `response_format`, you have the flexibility to customize how the output is parsed and presented, making it more user-friendly. To demonstrate this, we’ll add a format method to our `MathReasoning` model. This method will define the logic for transforming the raw JSON response into a more human-readable and accessible format."
"When defining a `response_format`, you have the flexibility to customize how the output is parsed and presented, making it more user-friendly. To demonstrate this, we’ll add a `format` method to our `MathReasoning` model. This method will define the logic for transforming the raw JSON response into a more human-readable and accessible format."
]
},
{
Expand Down Expand Up @@ -244,7 +244,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -278,7 +278,7 @@
"ChatResult(chat_id=None, chat_history=[{'content': 'how can I solve 8x + 7 = -23', 'role': 'assistant', 'name': 'User_proxy'}, {'content': 'Step 1: To solve the equation 8x + 7 = -23, we need to isolate x. Start by subtracting 7 from both sides to get rid of the constant term on the left side.\\n Output: 8x + 7 - 7 = -23 - 7\\nStep 2: By performing the subtraction, we simplify the equation to 8x = -30.\\n Output: 8x = -30\\nStep 3: Next, divide both sides by 8 to solve for x.\\n Output: x = -30 / 8\\nStep 4: Simplify the division to find x. -30 divided by 8 gives us -3.75.\\n Output: x = -3.75\\n\\nFinal Answer: x = -3.75', 'role': 'user', 'name': 'Math_solver'}], summary='Step 1: To solve the equation 8x + 7 = -23, we need to isolate x. Start by subtracting 7 from both sides to get rid of the constant term on the left side.\\n Output: 8x + 7 - 7 = -23 - 7\\nStep 2: By performing the subtraction, we simplify the equation to 8x = -30.\\n Output: 8x = -30\\nStep 3: Next, divide both sides by 8 to solve for x.\\n Output: x = -30 / 8\\nStep 4: Simplify the division to find x. -30 divided by 8 gives us -3.75.\\n Output: x = -3.75\\n\\nFinal Answer: x = -3.75', cost={'usage_including_cached_inference': {'total_cost': 0.003085, 'gpt-4o-2024-08-06': {'cost': 0.003085, 'prompt_tokens': 582, 'completion_tokens': 163, 'total_tokens': 745}}, 'usage_excluding_cached_inference': {'total_cost': 0}}, human_input=[])"
]
},
"execution_count": 7,
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
Expand Down Expand Up @@ -310,7 +310,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"outputs": [
{
Expand Down Expand Up @@ -338,7 +338,7 @@
"ChatResult(chat_id=None, chat_history=[{'content': 'solve 3 + 4 by calling appropriate function', 'role': 'assistant', 'name': 'User_proxy'}, {'tool_calls': [{'id': 'call_cp953ANv0S6J6iwrIdMpvLFm', 'function': {'arguments': '{\"x\":3,\"y\":4}', 'name': 'add'}, 'type': 'function'}], 'content': None, 'role': 'assistant'}], summary='', cost={'usage_including_cached_inference': {'total_cost': 0.001715, 'gpt-4o-2024-08-06': {'cost': 0.001715, 'prompt_tokens': 618, 'completion_tokens': 17, 'total_tokens': 635}}, 'usage_excluding_cached_inference': {'total_cost': 0}}, human_input=[])"
]
},
"execution_count": 8,
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
Expand Down

0 comments on commit a67ad8e

Please sign in to comment.