Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLM Templates - Created vision_gpt_explain_image llm application #964

Merged
merged 9 commits into from
Dec 3, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,8 @@ const CreateAppStatusModal: React.FC<Props & React.ComponentProps<typeof Modal>>
type === "success"
? "success"
: type === "error"
? "danger"
: "secondary"
? "danger"
: "secondary"
}
strong={Object.keys(messages)[ix] === "success"}
>
Expand Down
50 changes: 50 additions & 0 deletions examples/vision_gpt_explain_image/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import agenta as ag
from openai import OpenAI


client = OpenAI()


SYSTEM_PROMPT = "You are an expert in reading images you look into details, you answer in accurate language."
HUMAN_PROMPT = "Please compare two images"

ag.init(app_name="explain_image", base_name="app")
aybruhm marked this conversation as resolved.
Show resolved Hide resolved
ag.config.default(
temperature=ag.FloatParam(0.5, 0, 1),
max_tokens=ag.IntParam(300, 1, 4000),
prompt_system=ag.TextParam(SYSTEM_PROMPT),
prompt_human=ag.TextParam(HUMAN_PROMPT),
)
aybruhm marked this conversation as resolved.
Show resolved Hide resolved


@ag.entrypoint
def explain(
image_one: ag.FileInputURL,
image_two: ag.FileInputURL,
) -> str:
messages = [{"role": "system", "content": ag.config.prompt_system}] + [
{
"role": "user",
"content": [
{"type": "text", "text": ag.config.prompt_human},
{
"type": "image_url",
"image_url": {
"url": image_one,
},
},
{
"type": "image_url",
"image_url": {
"url": image_two,
},
},
],
}
]
chat_completion = client.chat.completions.create(
model="gpt-4-vision-preview",
messages=messages,
max_tokens=max_tokens,
)
return chat_completion.choices[0].message.content
2 changes: 2 additions & 0 deletions examples/vision_gpt_explain_image/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
agenta
openai
Loading