Chatlas in a shinyapp: How to specify an uploaded file as the tool argument?
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 35/100
調査の方向性
ChatOpenAI.register_tool と handle_user_input コールバックから始め、アップロードされたファイルから get_data() がどのように定義されるかを追跡します。ユーザーデータまたはリアクティブデータをツール引数として利用可能にする、サポートされている方法を、アップロードされたファイルの場合も含めて特定します。この例で利用できる程度に、その動作が実装されるか明確に文書化されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Chatlas is a really nice tool. I don't see a way to gain control over what arguments get passed to to a tool. Some of these would come from the LLM but some might be based on user input (e.g., a dataset dropdown). In the below I'd like to get the tool to use the get_data() as the argument. Is there a way to do something like this?
chat_client.register_tool(get_data_summary, dct=get_data())
from shiny import App, ui, render, reactive
import pandas as pd
import os
import json
import requests
from pydantic import BaseModel, Field
from chatlas import ChatOpenAI
from dotenv import load_dotenv
load_dotenv()
# if this app doesn't run check that you have set the correct
# Python interpreter
# you can set this using the command pallette and typing
# "Select: Python Interpreter"
# There is also a button you can click in the bottom left of VS Code
# to select the Python interpreter
# to stop the app, press Ctrl+C in the terminal
class GetCurrentTemperature(BaseModel):
"""
Get the current weather given a latitude and longitude.
You MUST provide both latitude and longitude as numbers.
If the user provides a location name (not latitude/longitude),
you MUST first call the 'get_lat_long' tool to obtain the coordinates
then call this tool with those coordinates.
"""
latitude: float = Field(
description="The latitude of the location. Must be a float."
)
longitude: float = Field(
description="The longitude of the location. Must be a float."
)
def get_current_temperature(latitude: float, longitude: float) -> dict:
lat_lng = f"latitude={latitude}&longitude={longitude}"
url = f"https://api.open-meteo.com/v1/forecast?{lat_lng}¤t=temperature_2m,wind_speed_10m&hourly=temperature_2m,relative_humidity_2m,wind_speed_10m"
response = requests.get(url)
js = response.json()
return js["current"]
class GetLatLong(BaseModel):
"""
Use this tool to get the latitude and longitude for a location name provided by the user.
If the user asks for weather and only provides a location name, call this tool first to get coordinates.
"""
location: str = Field(
description="The location name to get latitude and longitude for. Must be a string."
)
def get_lat_long(location: str) -> dict:
url = f"https://geocode.maps.co/search?q='{location}'&api_key={os.getenv('GEO_API_KEY')}"
response = requests.get(url)
js = response.json()
if len(js) == 0:
raise ValueError(
f"Could not find location: {location}. Try to determine the location from the LLM response and call this tool again with the new location."
)
else:
return {"latitude": float(js[0]["lat"]), "longitude": float(js[0]["lon"])}
def get_data_summary(dct: dict = {"a": [1, 2, 3], "b": [4, 5, 6]}) -> str:
"""
Use this tool to get summary statistics for a dictionary provided by the user.
"""
df = (
pd.DataFrame(dct)
.describe()
.T.reset_index()
.rename(columns={"index": "Statistic"})
)
return df.to_html(classes="table table-striped", index=False)
app_ui = ui.page_sidebar(
ui.sidebar(
ui.input_file("file", "Upload CSV File", accept=[".csv"]),
ui.output_data_frame("table"),
),
ui.panel_title("Weather Assistant"),
ui.chat_ui(id="my_chat"),
title="Weather Assistant",
)
start_messages = "Some example questions to ask the assistant:"
start_messages += "</br><span class='suggestion submit'>What is the lat-long for the Rady School of Management?</span>"
start_messages += "</br><span class='suggestion submit'>What is the weather like in New York City today?</span>"
start_messages += ("</br><span class='suggestion submit'>Summarize the uploaded file</span>")
def server(input, output, session):
chat = ui.Chat(id="my_chat", messages=[start_messages])
@reactive.calc
def get_dataframe():
if not input.file():
return pd.DataFrame()
file_path = input.file()[0]["datapath"]
df = pd.read_csv(file_path)
return df
@reactive.calc
def get_data():
return get_dataframe().to_dict(orient="records")
@render.data_frame
def table():
df = get_dataframe()
if df.empty:
return pd.DataFrame()
return df
chat_client = ChatOpenAI(
model="gpt-4o",
api_key=os.getenv("OPENAI_API_KEY"),
)
chat_client.register_tool(get_lat_long, model=GetLatLong)
chat_client.register_tool(get_current_temperature, model=GetCurrentTemperature)
chat_client.register_tool(get_data_summary)
@chat.on_user_submit
async def handle_user_input(user_input: str):
response = await chat_client.stream_async(user_input)
await chat.append_message_stream(response)
app = App(app_ui, server)
- 主要言語
- Python
- スター
- 179
- フォーク
- 32
- 平均マージ
- 1日 3時間
- マージ済み PR(30日)
- 10
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
posit-dev/chatlas のほかの issue
-
A streaming text delta that repeats everything streamed so far is missing from the recorded turn対応中かも @cpsievert が 81 日前に担当しました。 オープンai-triage:done Priority: Medium
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
メンテナーはふだん 1 日以内に返信
-
ai-triage:needs-review documentation
難易度 2/5 1〜2日 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 3〜5日 初心者へのやさしさ 42/100
メンテナーはふだん 1 日以内に返信
-
難易度 4/5 1〜2日 初心者へのやさしさ 35/100
メンテナーはふだん 1 日以内に返信
-
ai-triage:done Priority: Low
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
メンテナーはふだん 1 日以内に返信
posit-dev/chatlas の issue をすべて見る
似ている issue
-
bot-triaged module: decompositions module: edge cases module: int overflow module: primTorch oncall: pt2 triage review
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
country:US rating:6 request-theme type:TV SHOW
難易度 1/5 1時間未満 初心者へのやさしさ 65/100
LizardByte/ThemerrDB#10501 · コメント 1 件 ·
-
triage/confirmed
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
agentscope-ai/agentscope#4563 ·
メンテナーはふだん 2 日以内に返信
-
comp/desktop desktop/chat P3 type/bug
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
NousResearch/hermes-agent#164451 ·
メンテナーはふだん 1 日以内に返信
-
external integration integration-submission
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
langchain-ai/docs#8426 ·
メンテナーはふだん 1 日以内に返信