Skip to content

Commit

Permalink
fixup! feat(chat): add integration
Browse files Browse the repository at this point in the history
Ref: #219

Signed-off-by: Tomas Dvorak <toomas2d@gmail.com>
  • Loading branch information
Tomas2D committed Nov 8, 2023
1 parent b57088e commit cf57cc0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
10 changes: 4 additions & 6 deletions examples/user/chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from genai.credentials import Credentials
from genai.model import Model
from genai.schemas import GenerateParams
from genai.schemas.chat import BaseMessage, ChatRole
from genai.schemas.chat import HumanMessage, SystemMessage
from genai.schemas.generate_params import ChatOptions

# make sure you have a .env file under genai root with
Expand All @@ -24,12 +24,10 @@
creds = Credentials(api_key, api_endpoint)
model = Model("meta-llama/llama-2-70b-chat", params=params, credentials=creds)


prompt = "What is NLP and how it has evolved over the years?"
response = model.chat(
[
BaseMessage(
role=ChatRole.system,
SystemMessage(
content="""You are a helpful, respectful and honest assistant.
Always answer as helpfully as possible, while being safe.
Your answers should not include any harmful, unethical, racist, sexist, toxic, dangerous, or illegal content.
Expand All @@ -38,7 +36,7 @@
If you don't know the answer to a question, please don't share false information.
""",
),
BaseMessage(role=ChatRole.user, content=prompt),
HumanMessage(content=prompt),
]
)
print(f"Conversation ID: {response.conversation_id}")
Expand All @@ -48,7 +46,7 @@
prompt = "How can I start?"
response = model.chat(
[
BaseMessage(role=ChatRole.user, content=prompt),
HumanMessage(content=prompt),
],
options=ChatOptions(
conversation_id=response.conversation_id,
Expand Down
14 changes: 14 additions & 0 deletions src/genai/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
from genai.schemas.chat import (
AIMessage,
BaseMessage,
ChatRole,
HumanMessage,
SystemMessage,
)
from genai.schemas.descriptions import Descriptions
from genai.schemas.files_params import FileListParams, MultipartFormData
from genai.schemas.generate_params import (
ChatOptions,
GenerateParams,
LengthPenalty,
Return,
Expand All @@ -21,6 +29,7 @@
"LengthPenalty",
"Return",
"ReturnOptions",
"ChatOptions",
"TokenParams",
"HistoryParams",
"GenerateResult",
Expand All @@ -30,4 +39,9 @@
"TunesListParams",
"CreateTuneParams",
"CreateTuneHyperParams",
"HumanMessage",
"SystemMessage",
"BaseMessage",
"ChatRole",
"AIMessage",
]

0 comments on commit cf57cc0

Please sign in to comment.