-
Notifications
You must be signed in to change notification settings - Fork 226
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1080 from Agenta-AI/feat/templates
Add async version of baby name generator app
- Loading branch information
Showing
4 changed files
with
93 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from agenta import FloatParam, TextParam | ||
import agenta as ag | ||
from openai import AsyncOpenAI | ||
|
||
client = AsyncOpenAI() | ||
|
||
default_prompt = ( | ||
"Give me 10 names for a baby from this country {country} with gender {gender}!!!!" | ||
) | ||
|
||
ag.init() | ||
ag.config.default( | ||
temperature=FloatParam(0.2), prompt_template=TextParam(default_prompt) | ||
) | ||
|
||
|
||
@ag.entrypoint | ||
async def generate(country: str, gender: str) -> str: | ||
""" | ||
Generate a baby name based on the given country and gender. | ||
Args: | ||
country (str): The country to generate the name from. | ||
gender (str): The gender of the baby. | ||
Returns: | ||
str: The generated baby name. | ||
""" | ||
prompt = ag.config.prompt_template.format(country=country, gender=gender) | ||
|
||
chat_completion = await client.chat.completions.create( | ||
model="gpt-3.5-turbo", messages=[{"role": "user", "content": prompt}] | ||
) | ||
return chat_completion.choices[0].message.content |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,49 @@ | ||
# Using this template | ||
# Extraction using OpenAI Functions and Langchain" | ||
|
||
Please make sure to create a `.env` file with your OpenAI API key before running the app. | ||
OPENAI_API_KEY=sk-xxxxxxx | ||
|
||
You can find your keys here: | ||
https://platform.openai.com/account/api-keys | ||
This templates is designed to extracts job information (company name, job | ||
title, salary range) from a job description. It uses OpenAI Functions and | ||
Langchain. It runs with agenta. | ||
[Agenta](https://github.com/agenta-ai/agenta) is an open-source LLMOps | ||
platform that allows you to 1) quickly experiment and compare | ||
configuration for LLM apps 2) evaluate prompts and workflows 3) deploy | ||
applications easily. | ||
|
||
## How to use | ||
### 0. Prerequisites | ||
- Install the agenta CLI | ||
```bash | ||
pip install agenta-cli | ||
``` | ||
- Either create an account in [agenta cloud](https://cloud.agenta.ai/) or | ||
[self-host agenta](/self-host/host-locally) | ||
|
||
### 1. Clone the repository | ||
|
||
```bash | ||
git clone https://github.com/Agenta-AI/job_extractor_template | ||
``` | ||
|
||
### 2. Initialize the project | ||
|
||
```bash | ||
agenta init | ||
``` | ||
|
||
### 3. Setup your openAI API key | ||
Create a .env file by copying the .env.example file and add your openAI | ||
API key to it. | ||
```bash | ||
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx | ||
``` | ||
|
||
### 4. Deploy the application to agenta | ||
|
||
```bash | ||
agenta variant serve app.py | ||
``` | ||
|
||
### 5. Experiment with the prompts in a playground and evaluate different variants in agenta | ||
|
||
https://github.com/Agenta-AI/job_extractor_template/assets/4510758/30271188-8d46-4d02-8207-ddb60ad0e284 | ||
|
||
Go back to the [Getting started tutorial](https://docs.agenta.ai/getting-started) to continue |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters