Skip to content

Commit 8f72238

Browse files
authored
Merge pull request #16 from AmbireTech/feat/llm-options-override
LLM options override
2 parents 89e6cc0 + 73df3f1 commit 8f72238

File tree

6 files changed

+68
-6
lines changed

6 files changed

+68
-6
lines changed

lib/types/types.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ export type Strategy = {
4646
export type LlmProcessProps = {
4747
prompt: string
4848
model?: string
49+
llmOptionsOverride?: { [x: string]: any }
4950
}
5051

5152
export type LlmProcessOutput = {
@@ -62,6 +63,8 @@ export type ProcessAddressProps = {
6263
getPortfolio: (address: string) => Promise<PortfolioForNetwork[]>
6364
makePrompt: (props: PromptProps) => Promise<string>
6465
llmProcessor: (props: LlmProcessProps) => Promise<LlmProcessOutput>
66+
model?: string
67+
llmOptionsOverride?: any
6568
}
6669

6770
export type PromptProps = {

lib/utils/llm/gemini.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export async function callGemini(llmInput: LlmProcessProps): Promise<LlmProcessO
2121
generationConfig: {
2222
responseMimeType: 'application/json',
2323
responseSchema: StrategiesGoogleSchema
24-
}
24+
},
25+
...llmInput.llmOptionsOverride
2526
})
2627
const result = await aiModel.generateContent(llmInput.prompt)
2728
// console.log(JSON.stringify(result))

lib/utils/llm/grok.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ export async function callGrok(llmInput: LlmProcessProps): Promise<LlmProcessOut
3131
},
3232
{ role: 'user', content: llmInput.prompt }
3333
],
34-
response_format: zodResponseFormat(StrategiesZodSchema, 'strategies')
34+
response_format: zodResponseFormat(StrategiesZodSchema, 'strategies'),
35+
...llmInput.llmOptionsOverride
3536
})
3637

3738
const outputContent = completion.choices[0].message.content || '{}'

lib/utils/llm/structures/google.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const ActionGoogleSchema: Schema = {
1212
},
1313
description: {
1414
type: SchemaType.STRING,
15-
description: 'Free text describing the action',
15+
description:
16+
'Free text describing the action concerning the related tokens, the platform to use and expected APY',
1617
nullable: false
1718
},
1819
platforms: {

lib/utils/llm/structures/zod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ export const ActionZodSchema = z.object({
77
'Comma-separated list of symbols of the involved crypto currencies or tokens, for example: USDC, ETH'
88
}),
99
description: z.string({
10-
description: 'Free text describing the action concerning the related tokens'
10+
description:
11+
'Free text describing the action concerning the related tokens, the platform to use and expected APY'
1112
}),
1213
platforms: z.array(
1314
z.string({

lib/utils/portfolio.ts

Lines changed: 57 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,54 @@ import {
1212
NetworkPortfolioLibResponse
1313
} from '../types'
1414

15+
// import { z } from 'zod'
16+
// import { ACTION_OPERATION_TYPES, RISK_TYPES } from '..'
17+
// import { zodResponseFormat } from 'openai/helpers/zod'
18+
19+
// const ActionZodSchema = z.object({
20+
// tokens: z.string({
21+
// description:
22+
// 'Comma-separated list of symbols of the involved crypto currencies or tokens, for example: USDC, ETH'
23+
// }),
24+
// description: z.string({
25+
// description: 'Free text describing the action concerning the related tokens, the platform to use and expected APY'
26+
// }),
27+
// platforms: z.array(
28+
// z.string({
29+
// description: 'DeFi platform name'
30+
// }),
31+
// { description: 'The DeFi platform(s) which is to be used for the action' }
32+
// ),
33+
// networks: z.array(
34+
// z.string({
35+
// description: 'Lower-cased name of blockchain network'
36+
// }),
37+
// {
38+
// description:
39+
// 'The name of the blockchain network(s) which the action is to be executed on'
40+
// }
41+
// ),
42+
// operations: z.array(z.enum(ACTION_OPERATION_TYPES, { description: 'DeFi operation type' }), {
43+
// description: 'The DeFi operation type(s) used of the action'
44+
// }),
45+
// apy: z.string({
46+
// description:
47+
// 'The annual yield that can be expected from this action. Example values: 3%, 5%, 8-10%'
48+
// })
49+
// })
50+
51+
// const StrategyZodSchema = z.object({
52+
// name: z.string({ description: 'Name of the strategy' }),
53+
// risk: z.enum(RISK_TYPES, {
54+
// description: 'Risk level of the strategy'
55+
// }),
56+
// actions: z.array(ActionZodSchema, { description: 'List of actions for the strategy' })
57+
// })
58+
59+
// const StrategiesZodSchema = z.object({
60+
// strategies: z.array(StrategyZodSchema, { description: 'List of strategies' })
61+
// })
62+
1563
export async function getPortfolioForNetwork(
1664
address: string,
1765
networkId: string
@@ -68,7 +116,14 @@ export async function getPortfolioVelcroV3(address: string): Promise<PortfolioFo
68116
}
69117

70118
export const processAddress = async (
71-
{ address, getPortfolio, makePrompt, llmProcessor }: ProcessAddressProps = {
119+
{
120+
address,
121+
getPortfolio,
122+
makePrompt,
123+
llmProcessor,
124+
model,
125+
llmOptionsOverride
126+
}: ProcessAddressProps = {
72127
address: '0x69bfD720Dd188B8BB04C4b4D24442D3c15576D10',
73128
getPortfolio: getPortfolioVelcroV3,
74129
makePrompt: simplePrompt,
@@ -94,7 +149,7 @@ export const processAddress = async (
94149
}
95150

96151
const prompt = await makePrompt({ portfolio })
97-
const strategies = await llmProcessor({ prompt })
152+
const strategies = await llmProcessor({ prompt, model, llmOptionsOverride })
98153

99154
return {
100155
address,

0 commit comments

Comments
 (0)