You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/browser-rendering/how-to/ai.mdx
+63-66Lines changed: 63 additions & 66 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -116,49 +116,47 @@ export default {
116
116
}
117
117
118
118
} satisfiesExportedHandler<Env>;
119
-
120
119
```
121
120
122
121
## Call an LLM
123
122
124
123
Having the webpage text, the user's goal and output schema, we can now use an LLM to transform it to JSON according to the user's request.
125
-
The example below uses `@hf/thebloke/deepseek-coder-6.7b-instruct-awq` but other [models](/workers-ai/models/), or services like OpenAI, could be used with minimal changes:
124
+
The example below uses `@hf/thebloke/deepseek-coder-6.7b-instruct-awq` but other [models](/workers-ai/models/) or services like OpenAI, could be used with minimal changes:
const value = (text.match(/```(?:json)?\s*([\s\S]*?)\s*```/) || [null, text])[1];
156
-
try {
157
-
returnJSON.parse(value);
158
-
} catch(e) {
159
-
console.error(`${e} . Response: ${value}`)
160
-
}
150
+
// process response
151
+
const data =awaitresponse.json();
152
+
const text =data.result.response||'';
153
+
const value = (text.match(/```(?:json)?\s*([\s\S]*?)\s*```/) || [null, text])[1];
154
+
try {
155
+
returnJSON.parse(value);
156
+
} catch(e) {
157
+
console.error(`${e} . Response: ${value}`)
161
158
}
159
+
}
162
160
```
163
161
164
162
If you want to use Browser Rendering with OpenAI instead you'd just need to change the `aiUrl` endpoint and `requestBody` (or check out the [llm-scraper-worker](https://www.npmjs.com/package/llm-scraper-worker) package).
0 commit comments