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 startup technical ideas LLM chat app #958

Merged
merged 21 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
d05ca69
Feat - created file input url sdk type
aybruhm Nov 28, 2023
06aef48
Update - import FileInputURL to sdk __init__ modules
aybruhm Nov 28, 2023
9628573
Update - added annotation and default value to FileInputURL schema
aybruhm Nov 28, 2023
cc8894f
:art: Format - ran black
aybruhm Nov 28, 2023
dac5c47
Feat - introduce choice mixin to be used in MultipleChoiceParam sdk type
aybruhm Nov 28, 2023
e55115a
Update - modified multiple choice param schema override
aybruhm Nov 28, 2023
1fd9162
Update - add new parameters to application
aybruhm Nov 28, 2023
a7b16f5
Refactor - moved startup_feature_ideas from experimental to examples/
aybruhm Nov 28, 2023
9c45043
Cleanup - remove .gitignore file
aybruhm Nov 28, 2023
3f32477
Refactor - renamed startup_feature_ideas to startup_technical_ideas
aybruhm Nov 28, 2023
7e2be9f
Feat - added startup_technical_ideas llm app as a template to use
aybruhm Nov 28, 2023
b289e4c
Merge branch 'main' into gh/create-llm-app-temp-for-chat
aybruhm Nov 28, 2023
9031356
Cleanup - remove file input type from branch
aybruhm Nov 28, 2023
9328f4f
:art: Format - ran black
aybruhm Nov 28, 2023
1132b91
Refactor - added missing 't'
aybruhm Nov 28, 2023
6ce79ca
Cleanup - remove unused import(s)
aybruhm Nov 28, 2023
11f774e
Update - move model to ag.config parameter
aybruhm Nov 28, 2023
7883ea2
Update - revert back to original method
aybruhm Nov 28, 2023
17efa95
Update - added max_tokens to default parameters
aybruhm Nov 28, 2023
3064679
Update - remove startup_technical_ideas from agenta templates/ directory
aybruhm Nov 28, 2023
c3960d7
Update - make tiny adjustments
aybruhm Nov 29, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 9 additions & 13 deletions agenta-cli/agenta/sdk/agenta_decorator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@
import agenta
from fastapi import Body, FastAPI, UploadFile
from fastapi.middleware.cors import CORSMiddleware
from fastapi.openapi.models import Server
from fastapi.responses import JSONResponse

from .context import get_contexts, save_context
from .context import save_context
from .router import router as router
from .types import (
Context,
Expand Down Expand Up @@ -345,18 +344,15 @@ def find_in_schema(schema: dict, param_name: str, xparam: str):
f"Body_{func_name}_{endpoint}_post"
]["properties"]
for param_name, param_val in params.items():
# print(param_name, param_val)
if isinstance(param_val, MultipleChoiceParam):
if (
isinstance(param_val, inspect.Parameter)
and param_val.annotation is MultipleChoiceParam
):
subschema = find_in_schema(schema_to_override, param_name, "choice")
default = str(param_val)
param_choices = param_val.choices
choices = (
[default] + param_choices
if param_val not in param_choices
else param_choices
)
subschema["enum"] = choices
subschema["default"] = default if default in param_choices else choices[0]
default = param_val.default.choices[0]
param_choices = param_val.default.choices
subschema["enum"] = param_choices
subschema["default"] = default
if isinstance(param_val, FloatParam):
subschema = find_in_schema(schema_to_override, param_name, "float")
subschema["minimum"] = param_val.minval
Expand Down
35 changes: 17 additions & 18 deletions agenta-cli/agenta/sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,23 @@ def __modify_schema__(cls, field_schema):
)


class MultipleChoiceParam(str):
def __new__(cls, default: str = None, choices: List[str] = None):
if type(default) is list:
raise ValueError(
"The order of the parameters for MultipleChoiceParam is wrong! It's MultipleChoiceParam(default, choices) and not the opposite"
)
if default is None and choices:
# if a default value is not provided,
# uset the first value in the choices list
default = choices[0]

if default is None and not choices:
# raise error if no default value or choices is provided
raise ValueError("You must provide either a default value or choices")
class ChoiceMixin:
"""
Provides a mixin for managing a list of choices.
It is used as a base class for the MultipleChoiceParam class to \
provide the functionality for handling the choices attribute.
"""

instance = super().__new__(cls, default)
instance.choices = choices
instance.default = default
def __init__(self, choices: List[str] = None):
if not choices:
raise ValueError("You must provide either a list of choices")
self.choices = choices


class MultipleChoiceParam(str, ChoiceMixin):
def __new__(cls, choices: List[str] = None):
instance = super().__new__(cls, choices)
instance.default = choices[0]
return instance

@classmethod
Expand All @@ -106,7 +105,7 @@ class Message(BaseModel):
class MessagesInput(list):
"""Messages Input for Chat-completion.

Parameters:
Args:
messages (List[Dict[str, str]]): The list of messages inputs.
Required. Each message should be a dictionary with "role" and "content" keys.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Rename this file to .env
OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxx
9 changes: 9 additions & 0 deletions agenta-cli/agenta/templates/startup_technical_ideas/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Using this template

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

Go back to the [Getting started tutorial](https://docs.agenta.ai/getting-started) to continue
40 changes: 40 additions & 0 deletions agenta-cli/agenta/templates/startup_technical_ideas/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import agenta as ag
from agenta import FloatParam, MessagesInput, MultipleChoiceParam
from openai import OpenAI

client = OpenAI()

SYSTEM_PROMPT = "You have expertise in offering technical ideas to startups."
CHAT_LLM_GPT = [
"gpt-3.5-turbo",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-0301",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k-0613",
"gpt-4",
]

ag.init(app_name="technical_ideas", base_name="app")
ag.config.default(
temperature=FloatParam(0.2),
)


@ag.entrypoint
def chat(
model: MultipleChoiceParam = MultipleChoiceParam(CHAT_LLM_GPT),
inputs: MessagesInput = MessagesInput(
[{"role": "system", "content": SYSTEM_PROMPT}]
),
) -> str:
messages = [
{
"role": message["role"],
"content": message["content"],
}
for message in inputs
]
chat_completion = client.chat.completions.create(
model=model, messages=messages, temperature=ag.config.temperature
)
return chat_completion.choices[0].message.content
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
short_desc="Simple chat app that offers technical ideas to startups"
7 changes: 0 additions & 7 deletions examples/experimental/startup_feature_ideas/.gitignore

This file was deleted.

31 changes: 0 additions & 31 deletions examples/experimental/startup_feature_ideas/app.py

This file was deleted.

40 changes: 40 additions & 0 deletions examples/startup_technical_ideas/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import agenta as ag
from agenta import FloatParam, MessagesInput, MultipleChoiceParam
from openai import OpenAI

client = OpenAI()

SYSTEM_PROMPT = "You have expertise in offering technical ideas to startups."
CHAT_LLM_GPT = [
"gpt-3.5-turbo",
"gpt-3.5-turbo-16k",
"gpt-3.5-turbo-0301",
"gpt-3.5-turbo-0613",
"gpt-3.5-turbo-16k-0613",
"gpt-4",
]

ag.init(app_name="technical_ideas", base_name="app")
ag.config.default(
temperature=FloatParam(0.2),
)


@ag.entrypoint
def chat(
model: MultipleChoiceParam = MultipleChoiceParam(CHAT_LLM_GPT),
inputs: MessagesInput = MessagesInput(
[{"role": "system", "content": SYSTEM_PROMPT}]
aybruhm marked this conversation as resolved.
Show resolved Hide resolved
),
) -> str:
messages = [
aybruhm marked this conversation as resolved.
Show resolved Hide resolved
{
"role": message["role"],
"content": message["content"],
}
for message in inputs
]
chat_completion = client.chat.completions.create(
model=model, messages=messages, temperature=ag.config.temperature
)
return chat_completion.choices[0].message.content
2 changes: 2 additions & 0 deletions examples/startup_technical_ideas/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
agenta
openai
Loading