FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
python-agents-examples/basics/function_calling.py at main · archytus10/python-agents-examples · GitHub
archytus10
/
python-agents-examples
Public
forked from
livekit-examples/python-agents-examples
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
python-agents-examples
/
basics
/
function_calling.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
49 lines (39 loc) · 1.52 KB
Breadcrumbs
python-agents-examples
/
basics
/
function_calling.py
Copy path
File metadata and controls
49 lines (39 loc) · 1.52 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
## This is a basic example of how to use function calling.
## To test the function, you can ask the agent to print to the console!
import
logging
from
pathlib
import
Path
from
dotenv
import
load_dotenv
from
livekit
.
agents
import
JobContext
,
WorkerOptions
,
cli
from
livekit
.
agents
.
llm
import
function_tool
from
livekit
.
agents
.
voice
import
Agent
,
AgentSession
,
RunContext
from
livekit
.
plugins
import
deepgram
,
openai
,
silero
logger
=
logging
.
getLogger
(
"function-calling"
)
logger
.
setLevel
(
logging
.
INFO
)
load_dotenv
(
dotenv_path
=
Path
(
__file__
).
parent
.
parent
/
'.env'
)
class
FunctionAgent
(
Agent
):
def
__init__
(
self
)
->
None
:
super
().
__init__
(
instructions
=
"""
You are a helpful assistant communicating through voice. Don't use any unpronouncable characters.
Note: If asked to print to the console, use the `print_to_console` function.
"""
,
stt
=
deepgram
.
STT
(),
llm
=
openai
.
LLM
(
model
=
"gpt-4o"
),
tts
=
openai
.
TTS
(),
vad
=
silero
.
VAD
.
load
()
)
@
function_tool
async
def
print_to_console
(
self
,
context
:
RunContext
):
print
(
"Console Print Success!"
)
return
None
,
"I've printed to the console."
async
def
on_enter
(
self
):
self
.
session
.
generate_reply
()
async
def
entrypoint
(
ctx
:
JobContext
):
await
ctx
.
connect
()
session
=
AgentSession
()
await
session
.
start
(
agent
=
FunctionAgent
(),
room
=
ctx
.
room
)
if
__name__
==
"__main__"
:
cli
.
run_app
(
WorkerOptions
(
entrypoint_fnc
=
entrypoint
))
Back
|
FazBrowse Home
|
New Git URL