Travis Fischer 2023-06-24 12:24:14 -07:00
rodzic 0e3d19d466
commit 407d7fcfcd
5 zmienionych plików z 11 dodań i 15 usunięć

10
examples/replicate.ts vendored
Wyświetl plik

@ -5,19 +5,15 @@ import { z } from 'zod'
import { Agentic, ReplicateStableDiffusionTool } from '@/index' import { Agentic, ReplicateStableDiffusionTool } from '@/index'
async function main() { async function main() {
const openai = new OpenAIClient({ const openai = new OpenAIClient({ apiKey: process.env.OPENAI_API_KEY! })
apiKey: process.env.OPENAI_API_KEY!,
fetchOptions: {
timeout: false
}
})
const agentic = new Agentic({ openai }) const agentic = new Agentic({ openai })
const topic = process.argv[2] || 'san francisco' const topic = process.argv[2] || 'san francisco'
const res = await agentic const res = await agentic
.gpt4( .gpt4(
`Generate {{numImages}} images of {{topic}}. Use prompts that are artistic and creative.` ({ numImages, topic }) =>
`Generate ${numImages} images of ${topic}. Use prompts that are artistic and creative. The output should contain ${numImages} markdown images with descriptions.`
) )
.modelParams({ temperature: 1.0 }) .modelParams({ temperature: 1.0 })
.tools([new ReplicateStableDiffusionTool()]) .tools([new ReplicateStableDiffusionTool()])

Wyświetl plik

@ -33,7 +33,7 @@
"prepare": "husky install", "prepare": "husky install",
"pre-commit": "lint-staged", "pre-commit": "lint-staged",
"test": "run-s test:*", "test": "run-s test:*",
"test:unit": "ava", "test:unit": "NODE_OPTIONS='--loader=tsx --no-warnings' ava",
"test:prettier": "prettier \"**/*.{js,jsx,ts,tsx}\" --check", "test:prettier": "prettier \"**/*.{js,jsx,ts,tsx}\" --check",
"test:eslint": "eslint \"**/*.ts\"", "test:eslint": "eslint \"**/*.ts\"",
"test-cov": "c8 ava" "test-cov": "c8 ava"

Wyświetl plik

@ -1,9 +1,5 @@
lockfileVersion: '6.1' lockfileVersion: '6.1'
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false
dependencies: dependencies:
'@agentic/midjourney-fetch': '@agentic/midjourney-fetch':
specifier: ^1.0.1 specifier: ^1.0.1
@ -4807,3 +4803,7 @@ packages:
/zod@3.21.4: /zod@3.21.4:
resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==} resolution: {integrity: sha512-m46AKbrzKVzOzs/DZgVnG5H55N1sv1M8qZU3A8RIKbs3mrACDNeIOeilDymVb2HdmP8uwshOCF4uJ8uM9rCqJw==}
dev: false dev: false
settings:
autoInstallPeers: true
excludeLinksFromLockfile: false

Wyświetl plik

@ -241,6 +241,7 @@ export abstract class BaseChatCompletion<
// console.log('<<< completion', { messages, functions }) // console.log('<<< completion', { messages, functions })
const completion = await this._createChatCompletion(messages, functions) const completion = await this._createChatCompletion(messages, functions)
const message = completion.message const message = completion.message
const functionCall = message.function_call
// console.log('>>> completion', completion.message) // console.log('>>> completion', completion.message)
this._logger.info( this._logger.info(
@ -249,9 +250,7 @@ export abstract class BaseChatCompletion<
) )
ctx.metadata.completion = completion ctx.metadata.completion = completion
if (message.function_call && !message.content) { if (functionCall) {
const functionCall = message.function_call
if (!isUsingTools) { if (!isUsingTools) {
// TODO: not sure what we should do in this case... // TODO: not sure what we should do in this case...
output = functionCall output = functionCall

Wyświetl plik

@ -50,6 +50,7 @@ test('OpenAIChatCompletion - tools - weather', async (t) => {
) )
.call() .call()
// console.log(JSON.stringify(result, null, 2))
t.truthy(typeof result === 'object') t.truthy(typeof result === 'object')
t.truthy(typeof result.answer === 'number') t.truthy(typeof result.answer === 'number')
t.truthy(typeof result.units === 'string') t.truthy(typeof result.units === 'string')