-
Notifications
You must be signed in to change notification settings - Fork 10
fix open debug playground #93
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
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0a402d7
fix open debug playground
constantinidan d79c794
fix: linting
desaxce 5e3fe40
fix: vars handling + add examles for langchain
desaxce 261606d
fix: imports order linting
desaxce 7ac117e
fix: linting
desaxce cc40046
fix: process content as it used to
desaxce 0713dc9
fix: linting
desaxce 261e548
fix: examples typing
desaxce 7ac82ef
fix: make test idempotent
desaxce 9eb1c58
fix: rename variable
desaxce File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
OPENAI_API_KEY=sk- | ||
|
||
LITERAL_API_KEY="cl_" | ||
OPENAI_API_KEY="sk-" | ||
TAVILY_API_KEY="" | ||
LITERAL_API_KEY="lsk_" | ||
LITERAL_API_URL="http://localhost:3000" |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from literalai import LiteralClient | ||
|
||
from langchain_openai import ChatOpenAI # type: ignore | ||
from langchain_community.tools.tavily_search import TavilySearchResults | ||
|
||
from langchain.agents import create_tool_calling_agent | ||
from langchain.agents import AgentExecutor | ||
from langchain_core.messages import AIMessage, HumanMessage | ||
from langchain_core.runnables.config import RunnableConfig | ||
from langchain.agents.agent import BaseSingleActionAgent | ||
|
||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
model = ChatOpenAI(model="gpt-4o") | ||
search = TavilySearchResults(max_results=2) | ||
tools = [search] | ||
|
||
lai_client = LiteralClient() | ||
lai_prompt = lai_client.api.get_or_create_prompt( | ||
name="LC Agent", | ||
settings={ | ||
"model": "gpt-4o-mini", | ||
"top_p": 1, | ||
"provider": "openai", | ||
"max_tokens": 4095, | ||
"temperature": 0, | ||
"presence_penalty": 0, | ||
"frequency_penalty": 0, | ||
}, | ||
template_messages=[ | ||
{"role": "system", "content": "You are a helpful assistant"}, | ||
{"role": "assistant", "content": "{{chat_history}}"}, | ||
{"role": "user", "content": "{{input}}"}, | ||
{"role": "assistant", "content": "{{agent_scratchpad}}"}, | ||
], | ||
) | ||
prompt = lai_prompt.to_langchain_chat_prompt_template() | ||
|
||
agent: BaseSingleActionAgent = create_tool_calling_agent(model, tools, prompt) # type: ignore | ||
agent_executor = AgentExecutor(agent=agent, tools=tools) | ||
|
||
lai_client.reset_context() | ||
cb = lai_client.langchain_callback() | ||
|
||
agent_executor.invoke( | ||
{ | ||
"chat_history": [ | ||
# You can specify the intermediary messages as tuples too. | ||
# ("human", "hi! my name is bob"), | ||
# ("ai", "Hello Bob! How can I assist you today?") | ||
HumanMessage(content="hi! my name is bob"), | ||
AIMessage(content="Hello Bob! How can I assist you today?"), | ||
], | ||
"input": "whats the weather in sf?", | ||
}, | ||
config=RunnableConfig(callbacks=[cb], run_name="Weather SF"), | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
from langchain.chat_models import init_chat_model | ||
from literalai import LiteralClient | ||
from langchain.schema.runnable.config import RunnableConfig | ||
|
||
from dotenv import load_dotenv | ||
|
||
load_dotenv() | ||
|
||
lai = LiteralClient() | ||
|
||
prompt = lai.api.get_or_create_prompt( | ||
name="user intent", | ||
template_messages=[ | ||
{"role": "system", "content": "You're a helpful assistant."}, | ||
{"role": "user", "content": "{{user_message}}"}, | ||
], | ||
settings={ | ||
"provider": "openai", | ||
"model": "gpt-4o-mini", | ||
"temperature": 0, | ||
"max_tokens": 4095, | ||
"top_p": 1, | ||
"frequency_penalty": 0, | ||
"presence_penalty": 0, | ||
}, | ||
) | ||
messages = prompt.to_langchain_chat_prompt_template() | ||
|
||
inp = messages.format_messages( | ||
user_message="The screen is cracked, there are scratches on the surface, and a component is missing." | ||
) | ||
cb = lai.langchain_callback() | ||
|
||
# Returns a langchain_openai.ChatOpenAI instance. | ||
gpt_4o = init_chat_model( | ||
model_provider=prompt.provider, | ||
**prompt.settings, | ||
) | ||
print(gpt_4o.invoke(inp, config=RunnableConfig(callbacks=[cb]))) | ||
|
||
lai.flush_and_stop() |
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
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
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
as this is an example, can you plz change to a more explicit variable name ?