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: add STACKITChatGenerator #1274

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

julian-risch
Copy link
Member

@julian-risch julian-risch commented Jan 3, 2025

Related Issues

Proposed Changes:

  • Add a new integration with STACKITChatGenerator component that inherits from OpenAIChatGenerator but overwrites _prepare_api_call
  • Add unit and integration tests
  • Add three examples

How did you test it?

Ran unit tests, integration tests, and the examples locally.

Notes for the reviewer

I was thinking about setting a model by default, which would simplify initialization of the component. However, there is no obvious default value. That's why I made the model parameter mandatory.

I was surprised that I had to overwrite the _prepare_api_call method and wonder whether the implementation in OpenAIChatGenerator could cause problems for other OpenAI compatible model serving services users like to use.

There is already a draft PR for the integration page here and a draft for the documentation page here.

Checklist

@github-actions github-actions bot added the type:documentation Improvements or additions to documentation label Jan 3, 2025
@julian-risch julian-risch marked this pull request as ready for review January 8, 2025 09:16
@julian-risch julian-risch requested a review from a team as a code owner January 8, 2025 09:16
@julian-risch julian-risch requested review from mpangrazzi, dfokina and anakin87 and removed request for a team and mpangrazzi January 8, 2025 09:16
Copy link
Contributor

@mpangrazzi mpangrazzi left a comment

Choose a reason for hiding this comment

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

Looks good to me! I've added only two comments about some type warnings I am getting.

component = STACKITChatGenerator(model="neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8")
results = component.run(chat_messages)
assert len(results["replies"]) == 1
message: ChatMessage = results["replies"][0]
Copy link
Contributor

Choose a reason for hiding this comment

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

Here I think we can avoid mypy warning about annotation-unchecked adding None as test return type. This should tell mypy to type check the function bodies.

)
],
created=int(datetime.now(tz=pytz.timezone("UTC")).timestamp()),
usage={"prompt_tokens": 57, "completion_tokens": 40, "total_tokens": 97},
Copy link
Contributor

@mpangrazzi mpangrazzi Jan 9, 2025

Choose a reason for hiding this comment

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

This line may be:

from openai.types.completion_usage import CompletionUsage

# ...

usage=CompletionUsage(prompt_tokens=57, completion_tokens=40, total_tokens=97)

mypy trigger this if we add Any as mock method's return type

Copy link
Contributor

@dfokina dfokina left a comment

Choose a reason for hiding this comment

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

Some docstring comments

julian-risch and others added 2 commits January 9, 2025 14:12
…rators/stackit/chat/chat_generator.py

Co-authored-by: Daria Fokina <[email protected]>
Copy link
Member

@anakin87 anakin87 left a comment

Choose a reason for hiding this comment

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

Good job!
I left a few comments here and there.

We will release this after 2.9.0? My impression is that the implementation depends on that.

Is it worth creating an issue with this template to make sure we don't forget anything?

dynamic = ["version"]
description = 'An integration of STACKIT as a StackitChatGenerator'
readme = "README.md"
requires-python = ">=3.8"
Copy link
Member

Choose a reason for hiding this comment

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

Python 3.8 reached End Of Life (https://devguide.python.org/versions/), so I recommend supporting >=3.9.
Same for everything below.

Comment on lines +83 to +100
def _prepare_api_call( # noqa: PLR0913
self,
*,
messages: List[ChatMessage],
streaming_callback: Optional[StreamingCallbackT] = None,
generation_kwargs: Optional[Dict[str, Any]] = None,
tools: Optional[List[Tool]] = None,
tools_strict: Optional[bool] = None,
) -> Dict[str, Any]:
prepared_api_call = super(STACKITChatGenerator, self)._prepare_api_call(
messages=messages,
streaming_callback=streaming_callback,
generation_kwargs=generation_kwargs,
tools=tools,
tools_strict=tools_strict,
)
prepared_api_call.pop("tools")
return prepared_api_call
Copy link
Member

Choose a reason for hiding this comment

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

Now that deepset-ai/haystack#8702 has been merged, can we remove/refactor this part?

Comment on lines +173 to +174
"embedders: embedders tests",
"chat_generators: chat_generators tests",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"embedders: embedders tests",
"chat_generators: chat_generators tests",

these markers seem unused

@julian-risch
Copy link
Member Author

Thanks for all the feedback! This PR can wait until after 2.9 release, yes. I will also update issue to use the proper template for new integrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants