Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LlamaIndexTS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
LlamaIndexTS
Commits
62771058
Unverified
Commit
62771058
authored
11 months ago
by
Alex Yang
Committed by
GitHub
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
fix: empty tools (#772)
parent
ca348a65
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.changeset/brown-dodos-relax.md
+6
-0
6 additions, 0 deletions
.changeset/brown-dodos-relax.md
packages/core/src/llm/anthropic.ts
+8
-2
8 additions, 2 deletions
packages/core/src/llm/anthropic.ts
packages/core/src/llm/openai.ts
+8
-0
8 additions, 0 deletions
packages/core/src/llm/openai.ts
with
22 additions
and
2 deletions
.changeset/brown-dodos-relax.md
0 → 100644
+
6
−
0
View file @
62771058
---
"
llamaindex"
:
patch
"
@llamaindex/edge"
:
patch
---
fix: allow passing empty tools to llms
This diff is collapsed.
Click to expand it.
packages/core/src/llm/anthropic.ts
+
8
−
2
View file @
62771058
import
type
{
ClientOptions
}
from
"
@anthropic-ai/sdk
"
;
import
{
Anthropic
as
SDKAnthropic
}
from
"
@anthropic-ai/sdk
"
;
import
type
{
MessageCreateParamsNonStreaming
,
Tool
,
ToolResultBlockParam
,
ToolUseBlock
,
...
...
@@ -264,7 +265,7 @@ export class Anthropic extends ToolCallLLM<AnthropicAdditionalChatOptions> {
const
anthropic
=
this
.
session
.
anthropic
;
if
(
tools
)
{
const
response
=
await
anthropic
.
beta
.
tools
.
m
essage
s
.
c
reate
(
{
const
params
:
M
essage
C
reate
ParamsNonStreaming
=
{
messages
:
this
.
formatMessages
<
true
>
(
messages
),
tools
:
tools
.
map
(
Anthropic
.
toTool
),
model
:
this
.
getModelName
(
this
.
model
),
...
...
@@ -272,7 +273,12 @@ export class Anthropic extends ToolCallLLM<AnthropicAdditionalChatOptions> {
max_tokens
:
this
.
maxTokens
??
4096
,
top_p
:
this
.
topP
,
...(
systemPrompt
&&
{
system
:
systemPrompt
}),
});
};
// Remove tools if there are none, as it will cause an error
if
(
tools
.
length
===
0
)
{
delete
params
.
tools
;
}
const
response
=
await
anthropic
.
beta
.
tools
.
messages
.
create
(
params
);
const
toolUseBlock
=
response
.
content
.
find
(
(
content
):
content
is
ToolUseBlock
=>
content
.
type
===
"
tool_use
"
,
...
...
This diff is collapsed.
Click to expand it.
packages/core/src/llm/openai.ts
+
8
−
0
View file @
62771058
...
...
@@ -349,6 +349,14 @@ export class OpenAI extends ToolCallLLM<OpenAIAdditionalChatOptions> {
...
Object
.
assign
({},
this
.
additionalChatOptions
,
additionalChatOptions
),
};
if
(
Array
.
isArray
(
baseRequestParams
.
tools
)
&&
baseRequestParams
.
tools
.
length
===
0
)
{
// remove empty tools array to avoid OpenAI error
delete
baseRequestParams
.
tools
;
}
// Streaming
if
(
stream
)
{
return
this
.
streamChat
(
baseRequestParams
);
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment