From 70da2fc9ec36e5e69f5845b32026ec39b395afdf Mon Sep 17 00:00:00 2001 From: Michael Goin Date: Thu, 21 Nov 2024 17:08:39 -0500 Subject: [PATCH] Delete docs/source/guided_decoding.rst --- docs/source/guided_decoding.rst | 47 --------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 docs/source/guided_decoding.rst diff --git a/docs/source/guided_decoding.rst b/docs/source/guided_decoding.rst deleted file mode 100644 index 2108e54397de5..0000000000000 --- a/docs/source/guided_decoding.rst +++ /dev/null @@ -1,47 +0,0 @@ -This example is based on the OpenAI beta wrapper over the `client.chat.completions.create()` method that provides richer integrations with Python specific types. -Reference: https://github.com/openai/openai-python/blob/52357cff50bee57ef442e94d78a0de38b4173fc2/src/openai/resources/beta/chat/completions.py#L100-L104 - - -```python -from typing import List -from pydantic import BaseModel -from openai import OpenAI - - -class Step(BaseModel): - explanation: str - output: str - - -class MathResponse(BaseModel): - steps: List[Step] - final_answer: str - - -client = OpenAI(base_url="http://0.0.0.0:8000/v1", api_key="dummy") -completion = client.beta.chat.completions.parse( - model="meta-llama/Llama-3.1-8B-Instruct", - messages=[ - {"role": "system", "content": "You are a helpful expert math tutor."}, - {"role": "user", "content": "Solve 8x + 31 = 2."}, - ], - response_format=MathResponse, - extra_body=dict(guided_decoding_backend="outlines"), -) - -message = completion.choices[0].message -print(message) -assert message.parsed -for i, step in enumerate(message.parsed.steps): - print(f"Step #{i}:", step) -print("Answer:", message.parsed.final_answer) -``` - -Output: -``` -ParsedChatCompletionMessage[MathResponse](content='{ "steps": [{ "explanation": "First, let\'s isolate the term with the variable \'x\'. To do this, we\'ll subtract 31 from both sides of the equation.", "output": "8x + 31 - 31 = 2 - 31"}, { "explanation": "By subtracting 31 from both sides, we simplify the equation to 8x = -29.", "output": "8x = -29"}, { "explanation": "Next, let\'s isolate \'x\' by dividing both sides of the equation by 8.", "output": "8x / 8 = -29 / 8"}], "final_answer": "x = -29/8" }', refusal=None, role='assistant', audio=None, function_call=None, tool_calls=[], parsed=MathResponse(steps=[Step(explanation="First, let's isolate the term with the variable 'x'. To do this, we'll subtract 31 from both sides of the equation.", output='8x + 31 - 31 = 2 - 31'), Step(explanation='By subtracting 31 from both sides, we simplify the equation to 8x = -29.', output='8x = -29'), Step(explanation="Next, let's isolate 'x' by dividing both sides of the equation by 8.", output='8x / 8 = -29 / 8')], final_answer='x = -29/8')) -Step #0: explanation="First, let's isolate the term with the variable 'x'. To do this, we'll subtract 31 from both sides of the equation." output='8x + 31 - 31 = 2 - 31' -Step #1: explanation='By subtracting 31 from both sides, we simplify the equation to 8x = -29.' output='8x = -29' -Step #2: explanation="Next, let's isolate 'x' by dividing both sides of the equation by 8." output='8x / 8 = -29 / 8' -Answer: x = -29/8 -``` \ No newline at end of file