-
Notifications
You must be signed in to change notification settings - Fork 13
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
Handle Callable-like types in get_request_model (eg streaming_callback) + Fix component output serialization #41
Conversation
…mponent output to avoid pydantic serialization errors (eg on OpenAI responses)
Updates:
I've tested with this sample pipeline: components:
llm:
init_parameters:
api_base_url: null
api_key:
env_vars:
- OPENAI_API_KEY
strict: true
type: env_var
generation_kwargs: {}
model: gpt-4o-mini
organization: null
streaming_callback: null
system_prompt: null
type: haystack.components.generators.openai.OpenAIGenerator
prompt_builder:
init_parameters:
required_variables: null
template: "\nGiven the following information, answer the question.\n\nContext:\n\
{% for document in documents %}\n {{ document.content }}\n{% endfor %}\n\
\nQuestion: {{question}}\nAnswer:\n"
variables: null
type: haystack.components.builders.prompt_builder.PromptBuilder
retriever:
init_parameters:
document_store:
init_parameters:
bm25_algorithm: BM25L
bm25_parameters: {}
bm25_tokenization_regex: (?u)\b\w\w+\b
embedding_similarity_function: dot_product
index: 69eb366f-b05a-4811-befe-ed9d49c59a23
type: haystack.document_stores.in_memory.document_store.InMemoryDocumentStore
filter_policy: replace
filters: null
return_embedding: false
scale_score: false
top_k: 10
type: haystack.components.retrievers.in_memory.embedding_retriever.InMemoryEmbeddingRetriever
text_embedder:
init_parameters:
batch_size: 32
config_kwargs: null
device:
device: mps
type: single
model: sentence-transformers/all-MiniLM-L6-v2
model_kwargs: null
normalize_embeddings: false
precision: float32
prefix: ''
progress_bar: true
suffix: ''
token:
env_vars:
- HF_API_TOKEN
- HF_TOKEN
strict: false
type: env_var
tokenizer_kwargs: null
truncate_dim: null
trust_remote_code: false
type: haystack.components.embedders.sentence_transformers_text_embedder.SentenceTransformersTextEmbedder
connections:
- receiver: retriever.query_embedding
sender: text_embedder.embedding
- receiver: prompt_builder.documents
sender: retriever.documents
- receiver: llm.prompt
sender: prompt_builder.prompt
max_runs_per_component: 100
metadata: {} And both deployment and calls works correctly now. Tested with: curl -X 'POST' \
'http://localhost:1416/pipeline' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"llm": {
"generation_kwargs": {}
},
"prompt_builder": {
"question": "How is the light written in equations?",
"template_variables": {}
},
"retriever": {
"filters": {},
"top_k": 0,
"scale_score": true,
"return_embedding": true
},
"text_embedder": {
"text": "The speed of light in a vacuum is 299,792,458 meters per second (approximately 186,282 miles per second). This is a universal constant, typically denoted as '\''c'\'' in physics equations."
}
}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! 🚀
I recently started experimenting with Haystack as a framework for RAG (Retrieval-Augmented Generation). During local testing, everything worked perfectly. However, when attempting to deploy a pipeline with a generator component using hayhooks deploy, I encountered an error related to the OpenAIGenerator. Here is the pipeline file I'm using:
And here is the error message I received:
Steps to ReproduceInstall dependencies with the following versions: EnvironmentPython version: 3.12.4
Would it be possible to confirm if this is a version mismatch or if there’s something wrong with how the generator component or its parameters are defined? Any help or guidance would be much appreciated! |
Hi @Yuyang105! I've tried to reproduce your error, but I didn't get it. What I've done: # setup a new virtual env
python -m venv .venv
# activate it
. .venv/bin/activate
# install hayhooks (will come with haystack-ai 2.8.0)
pip install hayhooks
# to use your version
pip install --no-deps haystack-ai==2.8.1rc2 then run hayhooks with: hayhooks run and in another shell instance
And pipeline is then correctly deployed. |
This should add to
handle_unsupported_types
theCallable
type support (which will be converted todict
, since it's not serializable by default by Pydantic).Probably not the neatest way, but should make deployment and docs work (ref #38 and #40)