@@ -42,6 +42,10 @@ import {
42
42
ServiceType ,
43
43
SearchResponse ,
44
44
ActionResponse ,
45
+ IVerifiableInferenceAdapter ,
46
+ VerifiableInferenceOptions ,
47
+ VerifiableInferenceResult ,
48
+ VerifiableInferenceProvider ,
45
49
TelemetrySettings ,
46
50
TokenizerType ,
47
51
} from "./types.ts" ;
@@ -181,6 +185,8 @@ export async function generateText({
181
185
maxSteps = 1 ,
182
186
stop,
183
187
customSystemPrompt,
188
+ verifiableInference = process . env . VERIFIABLE_INFERENCE_ENABLED === "true" ,
189
+ verifiableInferenceOptions,
184
190
} : {
185
191
runtime : IAgentRuntime ;
186
192
context : string ;
@@ -190,6 +196,9 @@ export async function generateText({
190
196
maxSteps ?: number ;
191
197
stop ?: string [ ] ;
192
198
customSystemPrompt ?: string ;
199
+ verifiableInference ?: boolean ;
200
+ verifiableInferenceAdapter ?: IVerifiableInferenceAdapter ;
201
+ verifiableInferenceOptions ?: VerifiableInferenceOptions ;
193
202
} ) : Promise < string > {
194
203
if ( ! context ) {
195
204
console . error ( "generateText context is empty" ) ;
@@ -201,8 +210,33 @@ export async function generateText({
201
210
elizaLogger . info ( "Generating text with options:" , {
202
211
modelProvider : runtime . modelProvider ,
203
212
model : modelClass ,
213
+ verifiableInference,
204
214
} ) ;
205
215
216
+ // If verifiable inference is requested and adapter is provided, use it
217
+ if ( verifiableInference && runtime . verifiableInferenceAdapter ) {
218
+ try {
219
+ const result =
220
+ await runtime . verifiableInferenceAdapter . generateText (
221
+ context ,
222
+ modelClass ,
223
+ verifiableInferenceOptions
224
+ ) ;
225
+
226
+ // Verify the proof
227
+ const isValid =
228
+ await runtime . verifiableInferenceAdapter . verifyProof ( result ) ;
229
+ if ( ! isValid ) {
230
+ throw new Error ( "Failed to verify inference proof" ) ;
231
+ }
232
+
233
+ return result . text ;
234
+ } catch ( error ) {
235
+ elizaLogger . error ( "Error in verifiable inference:" , error ) ;
236
+ throw error ;
237
+ }
238
+ }
239
+
206
240
const provider = runtime . modelProvider ;
207
241
const endpoint =
208
242
runtime . character . modelEndpointOverride || getEndpoint ( provider ) ;
@@ -345,7 +379,7 @@ export async function generateText({
345
379
} ) ;
346
380
347
381
response = openaiResponse ;
348
- elizaLogger . debug ( "Received response from OpenAI model." ) ;
382
+ console . log ( "Received response from OpenAI model." ) ;
349
383
break ;
350
384
}
351
385
@@ -1520,6 +1554,9 @@ export interface GenerationOptions {
1520
1554
stop ?: string [ ] ;
1521
1555
mode ?: "auto" | "json" | "tool" ;
1522
1556
experimental_providerMetadata ?: Record < string , unknown > ;
1557
+ verifiableInference ?: boolean ;
1558
+ verifiableInferenceAdapter ?: IVerifiableInferenceAdapter ;
1559
+ verifiableInferenceOptions ?: VerifiableInferenceOptions ;
1523
1560
}
1524
1561
1525
1562
/**
@@ -1551,6 +1588,9 @@ export const generateObject = async ({
1551
1588
schemaDescription,
1552
1589
stop,
1553
1590
mode = "json" ,
1591
+ verifiableInference = false ,
1592
+ verifiableInferenceAdapter,
1593
+ verifiableInferenceOptions,
1554
1594
} : GenerationOptions ) : Promise < GenerateObjectResult < unknown > > => {
1555
1595
if ( ! context ) {
1556
1596
const errorMessage = "generateObject context is empty" ;
@@ -1594,6 +1634,9 @@ export const generateObject = async ({
1594
1634
runtime,
1595
1635
context,
1596
1636
modelClass,
1637
+ verifiableInference,
1638
+ verifiableInferenceAdapter,
1639
+ verifiableInferenceOptions,
1597
1640
} ) ;
1598
1641
1599
1642
return response ;
@@ -1619,6 +1662,9 @@ interface ProviderOptions {
1619
1662
modelOptions : ModelSettings ;
1620
1663
modelClass : ModelClass ;
1621
1664
context : string ;
1665
+ verifiableInference ?: boolean ;
1666
+ verifiableInferenceAdapter ?: IVerifiableInferenceAdapter ;
1667
+ verifiableInferenceOptions ?: VerifiableInferenceOptions ;
1622
1668
}
1623
1669
1624
1670
/**
@@ -1630,7 +1676,15 @@ interface ProviderOptions {
1630
1676
export async function handleProvider (
1631
1677
options : ProviderOptions
1632
1678
) : Promise < GenerateObjectResult < unknown > > {
1633
- const { provider, runtime, context, modelClass } = options ;
1679
+ const {
1680
+ provider,
1681
+ runtime,
1682
+ context,
1683
+ modelClass,
1684
+ verifiableInference,
1685
+ verifiableInferenceAdapter,
1686
+ verifiableInferenceOptions,
1687
+ } = options ;
1634
1688
switch ( provider ) {
1635
1689
case ModelProviderName . OPENAI :
1636
1690
case ModelProviderName . ETERNALAI :
@@ -1681,7 +1735,7 @@ async function handleOpenAI({
1681
1735
schema,
1682
1736
schemaName,
1683
1737
schemaDescription,
1684
- mode,
1738
+ mode = "json" ,
1685
1739
modelOptions,
1686
1740
} : ProviderOptions ) : Promise < GenerateObjectResult < unknown > > {
1687
1741
const baseURL = models . openai . endpoint || undefined ;
@@ -1691,7 +1745,7 @@ async function handleOpenAI({
1691
1745
schema,
1692
1746
schemaName,
1693
1747
schemaDescription,
1694
- mode,
1748
+ mode : "json" ,
1695
1749
...modelOptions ,
1696
1750
} ) ;
1697
1751
}
@@ -1708,7 +1762,7 @@ async function handleAnthropic({
1708
1762
schema,
1709
1763
schemaName,
1710
1764
schemaDescription,
1711
- mode,
1765
+ mode = "json" ,
1712
1766
modelOptions,
1713
1767
} : ProviderOptions ) : Promise < GenerateObjectResult < unknown > > {
1714
1768
const anthropic = createAnthropic ( { apiKey } ) ;
@@ -1717,7 +1771,7 @@ async function handleAnthropic({
1717
1771
schema,
1718
1772
schemaName,
1719
1773
schemaDescription,
1720
- mode,
1774
+ mode : "json" ,
1721
1775
...modelOptions ,
1722
1776
} ) ;
1723
1777
}
@@ -1734,7 +1788,7 @@ async function handleGrok({
1734
1788
schema,
1735
1789
schemaName,
1736
1790
schemaDescription,
1737
- mode,
1791
+ mode = "json" ,
1738
1792
modelOptions,
1739
1793
} : ProviderOptions ) : Promise < GenerateObjectResult < unknown > > {
1740
1794
const grok = createOpenAI ( { apiKey, baseURL : models . grok . endpoint } ) ;
@@ -1743,7 +1797,7 @@ async function handleGrok({
1743
1797
schema,
1744
1798
schemaName,
1745
1799
schemaDescription,
1746
- mode,
1800
+ mode : "json" ,
1747
1801
...modelOptions ,
1748
1802
} ) ;
1749
1803
}
@@ -1760,7 +1814,7 @@ async function handleGroq({
1760
1814
schema,
1761
1815
schemaName,
1762
1816
schemaDescription,
1763
- mode,
1817
+ mode = "json" ,
1764
1818
modelOptions,
1765
1819
} : ProviderOptions ) : Promise < GenerateObjectResult < unknown > > {
1766
1820
const groq = createGroq ( { apiKey } ) ;
@@ -1769,7 +1823,7 @@ async function handleGroq({
1769
1823
schema,
1770
1824
schemaName,
1771
1825
schemaDescription,
1772
- mode,
1826
+ mode : "json" ,
1773
1827
...modelOptions ,
1774
1828
} ) ;
1775
1829
}
@@ -1786,7 +1840,7 @@ async function handleGoogle({
1786
1840
schema,
1787
1841
schemaName,
1788
1842
schemaDescription,
1789
- mode,
1843
+ mode = "json" ,
1790
1844
modelOptions,
1791
1845
} : ProviderOptions ) : Promise < GenerateObjectResult < unknown > > {
1792
1846
const google = createGoogleGenerativeAI ( ) ;
@@ -1795,7 +1849,7 @@ async function handleGoogle({
1795
1849
schema,
1796
1850
schemaName,
1797
1851
schemaDescription,
1798
- mode,
1852
+ mode : "json" ,
1799
1853
...modelOptions ,
1800
1854
} ) ;
1801
1855
}
@@ -1812,7 +1866,7 @@ async function handleRedPill({
1812
1866
schema,
1813
1867
schemaName,
1814
1868
schemaDescription,
1815
- mode,
1869
+ mode = "json" ,
1816
1870
modelOptions,
1817
1871
} : ProviderOptions ) : Promise < GenerateObjectResult < unknown > > {
1818
1872
const redPill = createOpenAI ( { apiKey, baseURL : models . redpill . endpoint } ) ;
@@ -1821,7 +1875,7 @@ async function handleRedPill({
1821
1875
schema,
1822
1876
schemaName,
1823
1877
schemaDescription,
1824
- mode,
1878
+ mode : "json" ,
1825
1879
...modelOptions ,
1826
1880
} ) ;
1827
1881
}
@@ -1838,7 +1892,7 @@ async function handleOpenRouter({
1838
1892
schema,
1839
1893
schemaName,
1840
1894
schemaDescription,
1841
- mode,
1895
+ mode = "json" ,
1842
1896
modelOptions,
1843
1897
} : ProviderOptions ) : Promise < GenerateObjectResult < unknown > > {
1844
1898
const openRouter = createOpenAI ( {
@@ -1850,7 +1904,7 @@ async function handleOpenRouter({
1850
1904
schema,
1851
1905
schemaName,
1852
1906
schemaDescription,
1853
- mode,
1907
+ mode : "json" ,
1854
1908
...modelOptions ,
1855
1909
} ) ;
1856
1910
}
@@ -1866,7 +1920,7 @@ async function handleOllama({
1866
1920
schema,
1867
1921
schemaName,
1868
1922
schemaDescription,
1869
- mode,
1923
+ mode = "json" ,
1870
1924
modelOptions,
1871
1925
provider,
1872
1926
} : ProviderOptions ) : Promise < GenerateObjectResult < unknown > > {
@@ -1879,7 +1933,7 @@ async function handleOllama({
1879
1933
schema,
1880
1934
schemaName,
1881
1935
schemaDescription,
1882
- mode,
1936
+ mode : "json" ,
1883
1937
...modelOptions ,
1884
1938
} ) ;
1885
1939
}
0 commit comments