Skip to content

Commit 7e48162

Browse files
authored
Update README.md
1 parent 0c2da7a commit 7e48162

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

README.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,52 @@ output = client.chat.completions.generate_output(model="gpt-4", prompt=prompt, o
175175
This parameter is not merely a type decorator. It can also be used to overwrite the actual output type that GPT attempts to predict.
176176

177177

178+
### Few-Shot Prompting
179+
180+
Give examples to the model to explain tasks that are hard to explain:
181+
182+
```python
183+
class ExamplePrompt(PromptTemplate):
184+
185+
class Output(BaseLLMResponse):
186+
class Ingredient(BaseLLMResponse):
187+
name: str
188+
quantity: int
189+
190+
ingredients: list[Ingredient]
191+
192+
def system_prompt(self) -> str:
193+
return "Given a recipe, extract the ingredients."
194+
195+
def few_shot_examples(self) -> list[FewShotExample[Output]]:
196+
return [
197+
FewShotExample(
198+
input="Let's take two apples, three bananas, and four oranges.",
199+
output=self.Output(ingredients=[
200+
self.Output.Ingredient(name="apple", quantity=2),
201+
self.Output.Ingredient(name="banana", quantity=3),
202+
self.Output.Ingredient(name="orange", quantity=4),
203+
])
204+
),
205+
FewShotExample(
206+
input="My recipe requires five eggs and two cups of flour.",
207+
output=self.Output(ingredients=[
208+
self.Output.Ingredient(name="egg", quantity=5),
209+
self.Output.Ingredient(name="flour cups", quantity=2),
210+
])
211+
)
212+
]
213+
214+
def user_prompt(self) -> str:
215+
...
216+
```
217+
218+
219+
220+
178221
### Azure
179222

180-
e sure to use the `AzureChatModel` as the model when generating the output, which consists of the deployment_id and the corresponding base model (this is used for automatically reducing prompts if needed).
223+
Make sure to use the `AzureChatModel` as the model when generating the output, which consists of the deployment_id and the corresponding base model (this is used for automatically reducing prompts if needed).
181224
```python
182225
from typegpt.openai import AzureChatModel, TypeAzureOpenAI
183226

0 commit comments

Comments
 (0)