Skip to content

Commit

Permalink
Update openai.md (#214)
Browse files Browse the repository at this point in the history
* Update openai.md

The example was wrong. corrected it

* fix example

* fix

---------

Co-authored-by: anakin87 <[email protected]>
  • Loading branch information
rajib76 and anakin87 authored Jun 21, 2024
1 parent 3113ae9 commit b859248
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions integrations/openai.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,13 @@ from haystack.utils import Secret
from haystack.components.retrievers.in_memory import InMemoryBM25Retriever
from haystack.components.builders.prompt_builder import PromptBuilder
from haystack.components.generators import OpenAIGenerator
from haystack.document_stores.in_memory import InMemoryDocumentStore
from haystack import Document

docstore = InMemoryDocumentStore()
docstore.write_documents([Document(content="Rome is the capital of Italy"), Document(content="Paris is the capital of France")])

query = "What is the capital of France?"

template = """
Given the following information, answer the question.
Expand All @@ -92,21 +99,26 @@ Context:
{{ document.content }}
{% endfor %}
Question: What's the official language of {{ country }}?
Question: {{ query }}?
"""
pipe = Pipeline()

pipe.add_component("retriever", InMemoryBM25Retriever(document_store=document_store))
pipe.add_component("retriever", InMemoryBM25Retriever(document_store=docstore))
pipe.add_component("prompt_builder", PromptBuilder(template=template))
pipe.add_component("llm", OpenAIGenerator(model="gpt-4", api_key=Secret.from_token("YOUR_OPENAI_API_KEY")))
pipe.add_component("llm", OpenAIGenerator(api_key=Secret.from_token("YOUR_OPENAI_API_KEY"))
pipe.connect("retriever", "prompt_builder.documents")
pipe.connect("prompt_builder", "llm")

pipe.run({
res=pipe.run({
"prompt_builder": {
"country": "France"
"query": query
},
"retriever": {
"query": query
}
})
})

print(res)
```

#### Transcriber Models
Expand Down

0 comments on commit b859248

Please sign in to comment.