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

gpt model addn to conversation and seperate trimmed history + formatting #13

Merged
merged 4 commits into from
Aug 17, 2023

Conversation

adivik2000
Copy link
Contributor

This PR has the changes related to issues #10 and #11.

  • Now, we can load the default openai model and tiktoken should take care of the rest.
  • Have a separate trimmed history as a list that gets iterated every time a new message is added based on max_history_tokens. The storing part could be a bit redundant while we could just store the slicing start and end pointer where we'd slice the history list on the fly and return it. You tell me. How would you prefer it?

@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@@ -13,8 +13,11 @@ class Message(BaseModel):


class Conversation:
def __init__(self, history: List[Message] = [], id: Optional[str] = None, max_history_tokens: int = 200):
def __init__(
self, history: List[Message] = [], id: Optional[str] = None, max_history_tokens: int = 200, model: str = "gpt2"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's default to gpt3.5-turbo and use the corresponding encoder, tokenizer as well everywhere. This "gpt2" is confusing.


def add_message(self, role: str, content: str, name: Optional[str] = None) -> None:
message_dict = {"role": role, "content": content}
if name:
message_dict["name"] = name
message = Message(**message_dict)
self.history.append(message)
self.trim_history()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This call should be optional, only if the user sets it — it should be turned on.

def __init__(self, history: List[Message] = [], id: Optional[str] = None, max_history_tokens: int = 200):
def __init__(
self, history: List[Message] = [], id: Optional[str] = None, max_history_tokens: int = 200, model: str = "gpt2"
):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If max_history_tokens is set to None, and default should not be 200 — but None — do no trimming and let the damn thing error out.

Copy link
Owner

@NirantK NirantK left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Conversation should have a default model e.g. GPT3.5-Turbo, and empty __init__ call should work too.

@@ -83,7 +83,7 @@ Note that `agentai` automatically parses the Python Enum type (TemperatureUnit)
3. **Create a Conversation object and add messages**

```python
conversation = Conversation()
conversation = Conversation(model=GPT_MODEL)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've not formed a full opinion on whether Conversation should take a GPT_MODEL param at all — I'm inclined to believe it should be either more general e.g. create a LLM class and build around that OR (more preferred) — read this from env in some way.

In the mean time, merging this so that I can play with it and form stronger opinions.

@NirantK NirantK merged commit b716c95 into NirantK:main Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants