A python style implementation of Typechat.
Project description
typingchat
A python style implementation of Typechat
Useage
pip3 install pytypingchat
local install
pip3 install .
demo
Custom dataclass
from typingchat.core import TypeChat,OpenAIChat
from pydantic import BaseModel,Field
from typing import Literal
class Customer(BaseModel):
name: str = Field(description="Specify the customer's name")
class CoffeeDrink(BaseModel):
type: Literal["CoffeeDrink"] = Field(default="CoffeeDrink", description="Specify the type of coffee drink")
name: Literal["cappuccino", "flat white", "latte", "latte macchiato", "mocha", "chai latte"] = Field(None, description="Specify the name of the coffee drink")
count: int = Field(1, description="Specify the selected drink quantity")
def add_sugar(self, customer: Customer):
"""
add some sugar to coffee
Returns:
"""
return "add sugar success"
OPENAI_API_KEY = "sk-xxx"
OPENAI_MODEL = "gpt-3.5-turbo-0125"
chat = OpenAIChat(api_key=OPENAI_API_KEY,model=OPENAI_MODEL)
typechat = TypeChat(chat=chat)
coffee: CoffeeDrink = typechat.translate( #type: ignore
message="I want a mocha.",
obj=CoffeeDrink
)
coffee.model_dump() # {'type': 'CoffeeDrink', 'name': 'mocha', 'count': 1})
output
{'type': 'CoffeeDrink', 'name': 'mocha', 'count': 1})
use as function call
chat = OpenAIChat(api_key=OPENAI_API_KEY, model=OPENAI_MODEL)
typechat = TypeChat(chat=chat)
product = typechat.translate(
message="I want a flat white",
obj=CoffeeDrink
)
filter = lambda name: True if name in [product.add_sugar.__name__] else False
reply_messsage = typechat.operate(product, message="Add a little sugar to Tom's coffee", func_filter=filter,extra_dataclass=[Customer])
reply_message.content # The sugar has been successfully added to Tom's coffee.
References
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pytypingchat-0.0.1.tar.gz
(5.8 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytypingchat-0.0.1.tar.gz.
File metadata
- Download URL: pytypingchat-0.0.1.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2235e49298ff63a6859b67c4179eedf64e0b4cf409e0bfbf1aa0595649642a25
|
|
| MD5 |
f70a4d7d0a07be5ddfe5dbbc1850de89
|
|
| BLAKE2b-256 |
e76575c569807ddb7910371f403932b950f476a21b34c09cfea951563c70f3a9
|
File details
Details for the file pytypingchat-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pytypingchat-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e995dc67d89ee4a77c4c5279a2f6e51d103a423c5b577b93e300909cee4d2efa
|
|
| MD5 |
f075d2f698633b2c6f456b0304da47b5
|
|
| BLAKE2b-256 |
fc2f28b81482f40eb401ccedaf7a5956b4435d6edc8638f31854d83ecac6f140
|