You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It turns out that this function struggles to find the right answer. Its output (generated by `gpt-4o-mini`) varies a lot and typically includes Peggy Lee, who lived in a different century. This is because this short prompt actually requires real reasoning from the GPT: first listing everyone's birth and death years, then checking who overlapped with Chopin.
313
313
314
-
To get a smarter answer, we provide a `Reasoned` constructor for the output schema. Concretely, it requests the GPT answer to have two fields, `reasoning` and `result`. The GPT answers is more verbose, and therefore slower and more costly, but also more helpful:
314
+
To get a smarter answer, we provide a `gpt_reasoning` parameter to gpt-decorated functions. Concretely, it requests the GPT answer to have two fields, `reasoning` and `result` (the final result will have the reasoning under the `.__reasoning__` attribute). The GPT answers is more verbose, and therefore slower and more costly, but also more helpful:
315
315
- The `reasoning` field gives the GPT room to "think through" the problem and produce better answers.
316
316
- It is now possible for the user to see what the GPT's "reasoning" was, and whether a wrong answer was caused by a lack of knowledge, or logics, etc.
317
317
- It reduces the risk that some of GPT's reasoning and formatting ends up polluting the result's schema.
318
318
319
-
So let's just change our function's output type hint to `Reasoned[list[str]]` and observe the improvement:
319
+
So let's ask for a reasoning and observe the improvement:
320
320
321
321
```python
322
-
from gpt_function_decorator import gpt_function, Reasoned
The `gpt_function` decorator adds two parameters to the function it decorates:
353
355
-`gpt_model`: this allows the function's user to switch between `gpt-4o-mini` (the default, fast and cheap but less capable) and `gpt-4o` (any compatible version).
354
356
-`gpt_system_prompt`: this enables the user to tweak the answer as they would like by asking the GPT to focus on some aspects, or to roleplay.
357
+
-`gpt_reasoning` as described in the previous section.
355
358
-`gpt_debug`: this will cause the function to print the full prompt that it sends to the GPT (useful for troubleshooting or just getting a sense of what's going on).
356
359
357
360
As an example, let's start from this function:
@@ -419,8 +422,8 @@ GPTs are not yet fast and cheap enough to be used anywhere, but when they are it
419
422
For instance instead of having developers write zillions of messages to help users troubleshoot errors, we'll use a function like this:
0 commit comments