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

Feat/llm responses #376

Open
wants to merge 167 commits into
base: dev
Choose a base branch
from
Open

Feat/llm responses #376

wants to merge 167 commits into from

Conversation

NotBioWaste905
Copy link
Collaborator

@NotBioWaste905 NotBioWaste905 commented Jul 24, 2024

Description

Added functionality for calling LLMs via langchain API for utilizing them in responses and conditions.

Checklist

  • I have performed a self-review of the changes

List here tasks to complete in order to mark this PR as ready for review.

To Consider

  • Add tests
  • Update API reference / tutorials / guides
  • Update CONTRIBUTING.md

@NotBioWaste905 NotBioWaste905 requested a review from RLKRo July 24, 2024 12:22
Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

It appears this PR is a release PR (change its base from master if that is not the case).

Here's a release checklist:

  • Update package version
  • Update poetry.lock
  • Change PR merge option
  • Update template repo
  • Search for objects to be deprecated

@NotBioWaste905 NotBioWaste905 changed the base branch from master to dev July 24, 2024 12:22
chatsky/llm/methods.py Outdated Show resolved Hide resolved
chatsky/llm/methods.py Outdated Show resolved Hide resolved
chatsky/llm/filters.py Outdated Show resolved Hide resolved
chatsky/llm/wrapper.py Outdated Show resolved Hide resolved
chatsky/llm/wrapper.py Outdated Show resolved Hide resolved
chatsky/llm/wrapper.py Outdated Show resolved Hide resolved
chatsky/llm/wrapper.py Outdated Show resolved Hide resolved
tests/llm/test_model_response.py Outdated Show resolved Hide resolved
tests/llm/test_model_response.py Outdated Show resolved Hide resolved
tests/llm/test_model_response.py Outdated Show resolved Hide resolved
@RLKRo
Copy link
Member

RLKRo commented Aug 8, 2024

I got an idea for more complex prompts: we can allow passing responses as prompts instead of just strings.

And then it'd be possible to incorporate slots into a prompt:

model = LLM_API(prompt=rsp.slots.FilledTemplate("You are an experienced barista in a local coffeshop."
"Answer your customers questions about coffee and barista work.\n"
"Customer data:\nAge {person.age}\nGender: {person.gender}\nFavorite drink: {person.habits.drink}"
))

Copy link
Member

@RLKRo RLKRo left a comment

Choose a reason for hiding this comment

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

I've marked all resolved conversations as resolved (don't forget to put correct commit hash!).
There are still 25 unresolved conversations.
I've edited 9 of them with PROMPT REWORK or POSTPONED prefixes: the first ones are for me to resolve, the latter -- to be resolved in a later PR.

Please respond to the other 16 comments (plus the ones from this review): either with a commit hash of a commit that resolves it or with your comments regarding the suggestion.

raise NotImplemented

def __call__(self, ctx, request, response, model_name):
return self.call(ctx, request, model_name) + self.call(ctx, response, model_name)
Copy link
Member

Choose a reason for hiding this comment

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

Needs to be bitwise or:

Suggested change
return self.call(ctx, request, model_name) + self.call(ctx, response, model_name)
return self.call(ctx, request, model_name) | self.call(ctx, response, model_name)

Add tests. They did not catch this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Comment on lines 68 to 71
if request is not None and request.misc is not None and request.misc.get("important", None):
return self.Return.Request
if response is not None and response.misc is not None and response.misc.get("important", None):
return self.Return.Response
Copy link
Member

Choose a reason for hiding this comment

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

If both contain "important" this will return Request instead of Turn.
Implement this as MessageFilter.

Same for FromModel.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

}
return ExtractedGroupSlot(**res)

def __flatten_llm_group_slot(self, slot, parent_key=""):
Copy link
Member

Choose a reason for hiding this comment

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

You missed at least one in

            if isinstance(value, LLMGroupSlot):
                items.update(self.__flatten_llm_group_slot(value, new_key))

Add tests that use nested LLMGroupSlots.

raise ValueError

async def condition(
self, ctx: Context, prompt: str, method: BaseMethod, return_schema: Optional[BaseModel] = None
Copy link
Member

Choose a reason for hiding this comment

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

Why does condition not support context history?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

result.annotations = {"__generated_by_model__": self.name}
return result

async def condition(self, prompt: str, method: BaseMethod, return_schema=None):
Copy link
Member

Choose a reason for hiding this comment

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

Is it not possible to use message schema with log probs?

chatsky/llm/utils.py Outdated Show resolved Hide resolved
Copy link
Member

Choose a reason for hiding this comment

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

Some lines are clearly not covered by the tests:
Slots are not tested at all.

Run poe quick_test_coverage to generate html reports in htmlcov directory.
You can then view them (by opening htmlcov/index.html) to see which lines are not covered.

it will be reused across all the nodes and therefore it will store all dialogue history.
This is not advised if you are short on tokens or if you do not need to store all dialogue history.
Alternatively you can instantiate model object inside of RESPONSE field in the nodes you need.
Via `history` parameter you can set number of dialogue _turns_ that the model will use as the history. Default value is `5`.
Copy link
Member

Choose a reason for hiding this comment

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

This is out of place.
This should be in filtering_history or as a comment near the line where LLMResponse is initialized with history=0.

},
"tell": {
RESPONSE: rsp.FilledTemplate(
"So you are {person.username} and your occupation is {person.job}, right?"
Copy link
Member

Choose a reason for hiding this comment

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

person group slot does not allow partial extraction.
Add the flag, mention it, link to partial extraction tutorial.

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.

3 participants