alonsosilva commited on
Commit
93b7629
·
1 Parent(s): f730427

Add langsmith

Browse files
Files changed (2) hide show
  1. app.py +14 -2
  2. requirements.txt +1 -0
app.py CHANGED
@@ -1,3 +1,6 @@
 
 
 
1
  import solara
2
  from typing import Any, Callable, Optional, TypeVar, Union, cast, overload, List
3
  from typing_extensions import TypedDict
@@ -10,6 +13,9 @@ import openai
10
  from openai import OpenAI
11
  import instructor
12
  from pydantic import BaseModel, Field
 
 
 
13
 
14
  # NEEDED FOR INPUT TEXT AREA INSTEAD OF INPUT TEXT
15
  def use_change(el: reacton.core.Element, on_value: Callable[[Any], Any], enabled=True):
@@ -74,7 +80,12 @@ def InputTextarea(
74
 
75
  # EXTRACTION
76
  openai.api_key = os.environ['OPENAI_API_KEY']
77
- client = instructor.from_openai(OpenAI())
 
 
 
 
 
78
 
79
  class Person(BaseModel):
80
  name: str
@@ -138,7 +149,8 @@ def Page():
138
  aux.value = f"{obj}"
139
  def result():
140
  if messages.value != []:
141
- response(messages.value[-1]["content"])
 
142
  result = solara.lab.use_task(result, dependencies=[user_message_count])
143
  InputTextarea("Enter text:", value=text_block, continuous_update=False)
144
  solara.Button(label="Extract names and ages of users", on_click=send)
 
1
+ #from dotenv import load_dotenv, find_dotenv
2
+ #_ = load_dotenv(find_dotenv())
3
+
4
  import solara
5
  from typing import Any, Callable, Optional, TypeVar, Union, cast, overload, List
6
  from typing_extensions import TypedDict
 
13
  from openai import OpenAI
14
  import instructor
15
  from pydantic import BaseModel, Field
16
+ from langsmith import traceable
17
+ from langsmith.wrappers import wrap_openai
18
+
19
 
20
  # NEEDED FOR INPUT TEXT AREA INSTEAD OF INPUT TEXT
21
  def use_change(el: reacton.core.Element, on_value: Callable[[Any], Any], enabled=True):
 
80
 
81
  # EXTRACTION
82
  openai.api_key = os.environ['OPENAI_API_KEY']
83
+
84
+ # Wrap the OpenAI client with LangSmith
85
+ client = wrap_openai(OpenAI())
86
+
87
+ # Patch the client with instructor
88
+ client = instructor.from_openai(client, mode=instructor.Mode.TOOLS)
89
 
90
  class Person(BaseModel):
91
  name: str
 
149
  aux.value = f"{obj}"
150
  def result():
151
  if messages.value != []:
152
+ if messages.value[-1]["role"] == "user":
153
+ response(messages.value[-1]["content"])
154
  result = solara.lab.use_task(result, dependencies=[user_message_count])
155
  InputTextarea("Enter text:", value=text_block, continuous_update=False)
156
  solara.Button(label="Extract names and ages of users", on_click=send)
requirements.txt CHANGED
@@ -1,3 +1,4 @@
1
  solara==1.31.0
2
  openai==1.17.0
3
  instructor==1.1.0
 
 
1
  solara==1.31.0
2
  openai==1.17.0
3
  instructor==1.1.0
4
+ langsmith==0.1.47