This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given the fields `question`, produce the fields `answer`. | |
--- | |
Follow the following format. | |
Question: ${question} | |
Answer: ${answer} | |
--- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given the fields `question`, produce the fields `answer`. | |
--- | |
Follow the following format. | |
Question: ${question} | |
Answer: ${answer} | |
--- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given the fields `question`, produce the fields `answer`. | |
--- | |
Follow the following format. | |
Question: ${question} | |
Answer: ${answer} | |
--- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Given the fields `question`, produce the fields `answer`. | |
--- | |
Follow the following format. | |
Question: ${question} | |
Answer: ${answer} | |
--- |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Solve a question answering task with interleaving Thought, Action, Observation steps. Thought can reason about the current | |
situation, and Action can be three types: | |
2 (1) Search[entity], which searches the exact entity on Wikipedia and returns the first paragraph if it exists. If not, it | |
will return some similar entities to search. | |
3 (2) Lookup[keyword], which returns the next sentence containing keyword in the current passage. | |
4 (3) Finish[answer], which returns the answer and finishes the task. | |
5 Here are some examples. | |
6 Question: What is the elevation range for the area that the eastern sector of the Colorado orogeny extends into? | |
7 Action 1: Search[Colorado orogeny] | |
8 Observation 1: The Colorado orogeny was an episode of mountain building (an orogeny) in Colorado and surrounding areas. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
prompt = ''' | |
Sentence 1: "The church choir sings to the masses as they sing joyous songs from the book at a church." | |
Sentence 2: "The church has cracks in the ceiling." | |
''' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
context = ''' | |
Task: For each pair of sentences below, determine the relationship between them. Label them as: | |
0 (entailment) if the second sentence is a logical outcome or directly inferred from the first. | |
1 (neutral) if the second sentence is neither entailed nor contradicted by the first; it's just additional information. | |
2 (contradiction) if the second sentence contradicts or opposes the information in the first. | |
Example 1: | |
Sentence 1: "The cat sat on the mat." | |
Sentence 2: "The mat has a cat on it." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def generate_response(prompt, context): | |
openai.api_key = API_KEY | |
content = "You are a text classification model" | |
response = openai.ChatCompletion.create( | |
model="gpt-3.5-turbo", | |
messages=[ | |
{"role": "system", "content": content}, | |
{"role": "user", "content": f"Context: {context}. {prompt}"} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from haystack import Pipeline | |
from function_call import OpenAIFunctionCall | |
def create_pipeline(retriever, API_KEY): | |
p = Pipeline() | |
p.add_node(component=retriever, name="retriever", inputs=["Query"]) | |
p.add_node(component=OpenAIFunctionCall(API_KEY), name="OpenAIFunctionCall", inputs=["retriever"]) | |
return p |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import openai | |
from haystack.nodes.base import BaseComponent | |
from typing import List | |
import json | |
class OpenAIFunctionCall(BaseComponent): | |
outgoing_edges = 1 | |
def __init__(self, API_KEY): | |
self.API_KEY = API_KEY |