[JS] TypeError fetch failed.
Describe the bug
fetch failed
name: 'TypeError',
message: 'fetch failed',
stack: 'TypeError: fetch failed\n' +
' at Object.fetch (node:internal/deps/undici/undici:11731:11)\n' +
' at process.processTicksAndRejections (node:internal/process/task_queues:95:5)'
To Reproduce
import { generate } from '@genkit-ai/ai';
import { configureGenkit } from '@genkit-ai/core';
import { defineFlow, startFlowsServer } from '@genkit-ai/flow';
import * as z from 'zod';
import { ollama } from 'genkitx-ollama';
export default configureGenkit({
plugins: [
ollama({
models: [
{
name: 'gemma',
type: 'generate', // type: 'chat' | 'generate' | undefined
},
],
serverAddress: 'http://127.0.0.1:11434', // default local address
}),
],
logLevel: 'debug',
enableTracingAndMetrics: true,
});
export const dadJokeFlow = defineFlow(
{
name: 'dadJokeFlow',
inputSchema: z.string(),
outputSchema: z.string(),
},
async (topic) => {
const llmResponse = await generate({
prompt: `Give me a dad joke for ${topic}`,
model: 'ollama/gemma',
config: {
temperature: 1,
},
});
return llmResponse.text();
}
);
startFlowsServer();
Expected behavior
Response from ollama/gemma
Screenshots
Runtime (please complete the following information):
- OS: Darwin Kernel
- Version 23.4.0
Node version
- v18.19.1
Additional context
- ollama server is running on local
- Needs CORS headers?
Trace
{
"traceId": "45780520d500979a461453ac21dadb65",
"spans": {
"048a83860c076ee3": {
"spanId": "048a83860c076ee3",
"traceId": "45780520d500979a461453ac21dadb65",
"parentSpanId": "be88bc317935cc0a",
"startTime": 1716068267656,
"endTime": 1716068267712.037,
"attributes": {
"genkit:type": "action",
"genkit:name": "ollama/gemma",
"genkit:path": "/dev-run-action-wrapper/dadJokeFlow/dadJokeFlow/ollama/gemma",
"genkit:input": "{\"messages\":[{\"role\":\"user\",\"content\":[{\"text\":\"Give me a dad joke for math\"}]}],\"config\":{\"temperature\":1},\"tools\":[],\"output\":{\"format\":\"text\"}}",
"genkit:metadata:subtype": "model",
"genkit:state": "error"
},
"displayName": "ollama/gemma",
"links": [],
"instrumentationLibrary": {
"name": "genkit-tracer",
"version": "v1"
},
"spanKind": "INTERNAL",
"sameProcessAsParentSpan": {
"value": true
},
"status": {
"code": 2,
"message": "fetch failed"
},
"timeEvents": {
"timeEvent": [
{
"time": 1716068267711.6345,
"annotation": {
"attributes": {
"exception.type": "TypeError",
"exception.message": "fetch failed",
"exception.stacktrace": "TypeError: fetch failed\n at Object.fetch (node:internal/deps/undici/undici:11731:11)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
},
"description": "exception"
}
}
]
}
},
"be88bc317935cc0a": {
"spanId": "be88bc317935cc0a",
"traceId": "45780520d500979a461453ac21dadb65",
"parentSpanId": "64913606c2f8c50f",
"startTime": 1716068267606,
"endTime": 1716068267718.3179,
"attributes": {
"genkit:type": "flow",
"genkit:name": "dadJokeFlow",
"genkit:isRoot": true,
"genkit:path": "/dev-run-action-wrapper/dadJokeFlow/dadJokeFlow",
"genkit:metadata:flow:execution": "0",
"genkit:metadata:flow:name": "dadJokeFlow",
"genkit:metadata:flow:id": "1660b322-ad28-4ace-8906-69342a55c9a9",
"genkit:metadata:flow:dispatchType": "start",
"genkit:metadata:flow:state": "error",
"genkit:input": "\"math\"",
"genkit:state": "error"
},
"displayName": "dadJokeFlow",
"links": [],
"instrumentationLibrary": {
"name": "genkit-tracer",
"version": "v1"
},
"spanKind": "INTERNAL",
"sameProcessAsParentSpan": {
"value": true
},
"status": {
"code": 2,
"message": "fetch failed"
},
"timeEvents": {
"timeEvent": [
{
"time": 1716068267717.0923,
"annotation": {
"attributes": {
"exception.type": "TypeError",
"exception.message": "fetch failed",
"exception.stacktrace": "TypeError: fetch failed\n at Object.fetch (node:internal/deps/undici/undici:11731:11)\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)"
},
"description": "exception"
}
}
]
}
},
"64913606c2f8c50f": {
"spanId": "64913606c2f8c50f",
"traceId": "45780520d500979a461453ac21dadb65",
"startTime": 1716068267598,
"endTime": 1716068267723.0461,
"attributes": {
"genkit:type": "action",
"genkit:name": "dadJokeFlow",
"genkit:path": "/dev-run-action-wrapper/dadJokeFlow",
"genkit:input": "{\"start\":{\"input\":\"math\"}}",
"genkit:metadata:subtype": "flow",
"genkit:metadata:flow:wrapperAction": "true",
"genkit:output": "{\"flowId\":\"1660b322-ad28-4ace-8906-69342a55c9a9\",\"name\":\"dadJokeFlow\",\"startTime\":1716068267605,\"input\":\"math\",\"cache\":{},\"eventsTriggered\":{},\"blockedOnStep\":null,\"executions\":[{\"startTime\":1716068267606,\"traceIds\":[\"45780520d500979a461453ac21dadb65\"]}],\"operation\":{\"name\":\"1660b322-ad28-4ace-8906-69342a55c9a9\",\"done\":true,\"result\":{\"error\":\"fetch failed\",\"stacktrace\":\"TypeError: fetch failed\\n at Object.fetch (node:internal/deps/undici/undici:11731:11)\\n at process.processTicksAndRejections (node:internal/process/task_queues:95:5)\"}},\"traceContext\":\"{\\\"traceId\\\":\\\"45780520d500979a461453ac21dadb65\\\",\\\"spanId\\\":\\\"be88bc317935cc0a\\\",\\\"traceFlags\\\":1}\"}",
"genkit:state": "success"
},
"displayName": "dadJokeFlow",
"links": [],
"spanKind": "INTERNAL",
"parentSpanId": "885a06075d79204f",
"sameProcessAsParentSpan": {
"value": true
},
"status": {
"code": 0
},
"timeEvents": {
"timeEvent": []
},
"instrumentationLibrary": {
"name": "genkit-tracer",
"version": "v1"
}
}
}
}
P.S: Might be an undici issue.
Do you have ollama installed and serving on your local machine? What do you see when when you point your browser at http://127.0.0.1:11434
I am having the same issue.
I am having same issue as well. I have Ollama installed and going to http://127.0.0.1:11434/ shows message Ollama is running
Just to make sure, are you running ollama server and genkit start on the same machine (not in IDX, codespace, etc)?
Unfortunately the current error message is not very helpful, I've sent out #205 to address this, hopefully once it's out (in a few days) it'll help with troubleshooting.
A better error message is now released in version 0.5.1. Please give it another try.
this seems to be fixed. Let us know if the issues still persists.