-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #919 from parea-ai/PAI-1201-cook-book-using-parea-…
…on-class-and-test-using-decorator-on-fastapi-endpoint organize cookbook into folders
- Loading branch information
Showing
53 changed files
with
104 additions
and
15 deletions.
There are no files selected for viewing
This file contains 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
Empty file.
File renamed without changes.
3 changes: 1 addition & 2 deletions
3
parea/cookbook/tracing_anthropic_tool_use.py → ...k/anthropic/tracing_anthropic_tool_use.py
This file contains 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
This file contains 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
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import os | ||
|
||
from dotenv import load_dotenv | ||
from langchain_core.output_parsers import StrOutputParser | ||
from langchain_core.prompts import ChatPromptTemplate | ||
from langchain_openai import ChatOpenAI | ||
|
||
from parea import Parea, trace | ||
from parea.utils.trace_integrations.langchain import PareaAILangchainTracer | ||
|
||
load_dotenv() | ||
|
||
p = Parea(api_key=os.getenv("PAREA_API_KEY")) | ||
|
||
|
||
class LangChainModule: | ||
handler = PareaAILangchainTracer() | ||
|
||
def __init__(self): | ||
self.llm = ChatOpenAI(openai_api_key=os.getenv("OPENAI_API_KEY")) | ||
|
||
def get_chain(self): | ||
prompt = ChatPromptTemplate.from_messages([("user", "{input}")]) | ||
chain = prompt | self.llm | StrOutputParser() | ||
return chain | ||
|
||
@trace(name="langchain_caller_call") | ||
def __call__(self, query: str) -> str: | ||
chain = self.get_chain() | ||
return chain.invoke( | ||
{"input": "Write a Hello World program in Python using FastAPI."}, | ||
config={"callbacks": [self.handler]}, | ||
) | ||
|
||
|
||
class LLMCaller: | ||
def __init__(self, query: str): | ||
self.client = LangChainModule() | ||
self.query = query | ||
|
||
@trace(name="llm_caller_call") | ||
def __call__(self) -> str: | ||
return self.client(query=self.query) | ||
|
||
|
||
@trace | ||
def main(query: str) -> str: | ||
caller = LLMCaller(query=query) | ||
return caller() | ||
|
||
|
||
if __name__ == "__main__": | ||
result = main("Write a Hello World program in Python using FastAPI.") | ||
print(result) |
This file contains 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
This file contains 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
Empty file.
File renamed without changes.
Empty file.
File renamed without changes.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
from typing import List | ||
|
||
import os | ||
|
||
from dotenv import load_dotenv | ||
from openai import OpenAI | ||
|
||
from parea import Parea, trace | ||
|
||
load_dotenv() | ||
|
||
p = Parea(api_key=os.getenv("PAREA_API_KEY")) | ||
|
||
|
||
class LLMCaller: | ||
def __init__(self, messages: List[dict[str, str]]): | ||
self.messages = messages | ||
self.client = OpenAI(api_key=os.environ.get("OPENAI_API_KEY")) | ||
p.wrap_openai_client(self.client) | ||
|
||
@trace | ||
def __call__(self, model: str = "gpt-4o", temperature: float = 0.0) -> str: | ||
return self.client.chat.completions.create(model=model, temperature=temperature, messages=self.messages).choices[0].message.content | ||
|
||
|
||
@trace | ||
def main(topic: str) -> str: | ||
caller = LLMCaller( | ||
messages=[ | ||
{"role": "system", "content": "You are a debater making an argument on a topic."}, | ||
{"role": "user", "content": f"The discussion topic is {topic}"}, | ||
] | ||
) | ||
return caller() | ||
|
||
|
||
if __name__ == "__main__": | ||
result = main("The impact of climate change on the economy") | ||
print(result) |
File renamed without changes.
This file contains 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
This file contains 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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains 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
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.