Skip to content

Commit 41db207

Browse files
committed
examples/basic/fn-call-local-simple.py
1 parent f4e06f9 commit 41db207

5 files changed

Lines changed: 162909 additions & 39 deletions

File tree

examples/basic/fn-call-local-simple.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
#
5353
# agent = lr.ChatAgent(
5454
# lr.ChatAgentConfig(
55-
# llm=llm
55+
# llm=llm_cfg,
5656
# )
5757
# )
5858
#

examples/chainlit/chat-stream.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ async def on_chat_start():
5353
sys_msg = "You are a helpful assistant. Be concise in your answers."
5454
config = ChatAgentConfig(
5555
system_message=sys_msg,
56+
show_stats=False,
5657
)
5758
agent = ChatAgent(config)
5859
cl.user_session.set("agent", agent)

examples/docqa/chat_multi_extract.py

Lines changed: 27 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import json
1919
import os
2020

21+
import langroid.language_models as lm
2122
from langroid.mytypes import Entity
2223
from langroid.agent.special.doc_chat_agent import DocChatAgent, DocChatAgentConfig
2324
from langroid.parsing.parser import ParsingConfig
@@ -102,15 +103,24 @@ def lease_info(self, message: LeaseMessage) -> str:
102103
return "DONE " + json.dumps(message.terms.dict())
103104

104105

105-
class CLIOptions(BaseSettings):
106-
debug: bool = False
107-
fn_api: bool = False
108-
cache: bool = True
109-
110-
111-
def chat(opts: CLIOptions) -> None:
106+
@app.command()
107+
def main(
108+
debug: bool = typer.Option(False, "--debug", "-d", help="debug mode"),
109+
model: str = typer.Option("", "--model", "-m", help="model name"),
110+
nocache: bool = typer.Option(False, "--nocache", "-nc", help="don't use cache"),
111+
) -> None:
112+
set_global(
113+
Settings(
114+
debug=debug,
115+
cache=not nocache,
116+
)
117+
)
118+
llm_cfg = OpenAIGPTConfig(
119+
chat_model=model or lm.OpenAIChatModel.GPT4_TURBO,
120+
)
112121
doc_agent = DocChatAgent(
113122
DocChatAgentConfig(
123+
llm=llm_cfg,
114124
parsing=ParsingConfig(
115125
chunk_size=100,
116126
overlap=20,
@@ -138,9 +148,7 @@ def chat(opts: CLIOptions) -> None:
138148

139149
lease_extractor_agent = LeaseExtractorAgent(
140150
ChatAgentConfig(
141-
llm=OpenAIGPTConfig(),
142-
use_functions_api=opts.fn_api,
143-
use_tools=not opts.fn_api,
151+
llm=llm_cfg,
144152
vecdb=None,
145153
)
146154
)
@@ -151,43 +159,25 @@ def chat(opts: CLIOptions) -> None:
151159
name="LeaseExtractorAgent",
152160
interactive=False, # set to True to slow it down (hit enter to progress)
153161
system_message=f"""
154-
You have to collect some information about a Commercial Lease, but you do not
155-
have access to the lease itself.
162+
You have to collect some SPECIFIC STRUCTURED information
163+
about a Commercial Lease, as specified in the `lease_info` function/tool.
164+
But you do not have access to the lease itself.
156165
You can ask me questions about the lease, ONE AT A TIME, I will answer each
157-
question. You only need to collect info corresponding to the fields in this
158-
specified structure.
166+
question. You only need to collect info to fill the fields in the
167+
`field_info` function/tool.
159168
If I am unable to answer your question initially, try asking me
160169
differently. If I am still unable to answer after 3 tries, fill in
161170
{NO_ANSWER} for that field.
162171
When you have collected this info, present it to me using the
163172
'lease_info' function/tool.
173+
DO NOT USE THIS Function/tool UNTIL YOU HAVE ASKED QUESTIONS
174+
TO FILL IN ALL THE FIELDS.
175+
176+
Start by asking me for the start date of the lease.
164177
""",
165178
)
166179
lease_task.add_sub_task(doc_task)
167180
lease_task.run()
168181

169-
170-
@app.command()
171-
def main(
172-
debug: bool = typer.Option(False, "--debug", "-d", help="debug mode"),
173-
nocache: bool = typer.Option(False, "--nocache", "-nc", help="don't use cache"),
174-
fn_api: bool = typer.Option(False, "--fn_api", "-f", help="use functions api"),
175-
cache_type: str = typer.Option(
176-
"redis", "--cachetype", "-ct", help="redis or momento"
177-
),
178-
) -> None:
179-
cli_opts = CLIOptions(
180-
fn_api=fn_api,
181-
)
182-
set_global(
183-
Settings(
184-
debug=debug,
185-
cache=not nocache,
186-
cache_type=cache_type,
187-
)
188-
)
189-
chat(cli_opts)
190-
191-
192182
if __name__ == "__main__":
193183
app()

0 commit comments

Comments
 (0)