Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LlamaIndexTS
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
mirrored_repos
MachineLearning
run-llama
LlamaIndexTS
Commits
130b7992
Unverified
Commit
130b7992
authored
11 months ago
by
Marcus Schiesser
Committed by
GitHub
11 months ago
Browse files
Options
Downloads
Patches
Plain Diff
refactor: clean gemini embedding (#781)
parent
0d50b22d
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
examples/gemini/embedding.ts
+2
-2
2 additions, 2 deletions
examples/gemini/embedding.ts
packages/core/src/embeddings/GeminiEmbedding.ts
+9
-15
9 additions, 15 deletions
packages/core/src/embeddings/GeminiEmbedding.ts
packages/core/src/llm/gemini.ts
+0
-6
0 additions, 6 deletions
packages/core/src/llm/gemini.ts
with
11 additions
and
23 deletions
examples/gemini.ts
→
examples/gemini
/embedding
.ts
+
2
−
2
View file @
130b7992
import
{
GEMINI_MODEL
,
GeminiEmbedding
}
from
"
llamaindex
"
;
import
{
GEMINI_
EMBEDDING_
MODEL
,
GeminiEmbedding
}
from
"
llamaindex
"
;
async
function
main
()
{
async
function
main
()
{
if
(
!
process
.
env
.
GOOGLE_API_KEY
)
{
if
(
!
process
.
env
.
GOOGLE_API_KEY
)
{
throw
new
Error
(
"
Please set the GOOGLE_API_KEY environment variable.
"
);
throw
new
Error
(
"
Please set the GOOGLE_API_KEY environment variable.
"
);
}
}
const
embedModel
=
new
GeminiEmbedding
({
const
embedModel
=
new
GeminiEmbedding
({
model
:
GEMINI_MODEL
.
G
EM
INI_PRO
,
model
:
GEMINI_
EMBEDDING_
MODEL
.
EM
BEDDING_001
,
});
});
const
texts
=
[
"
hello
"
,
"
world
"
];
const
texts
=
[
"
hello
"
,
"
world
"
];
const
embeddings
=
await
embedModel
.
getTextEmbeddingsBatch
(
texts
);
const
embeddings
=
await
embedModel
.
getTextEmbeddingsBatch
(
texts
);
...
...
This diff is collapsed.
Click to expand it.
packages/core/src/embeddings/GeminiEmbedding.ts
+
9
−
15
View file @
130b7992
import
{
import
{
GeminiSessionStore
,
type
GeminiSession
}
from
"
../llm/gemini.js
"
;
GEMINI_MODEL
,
GeminiSessionStore
,
type
GeminiConfig
,
type
GeminiSession
,
}
from
"
../llm/gemini.js
"
;
import
{
BaseEmbedding
}
from
"
./types.js
"
;
import
{
BaseEmbedding
}
from
"
./types.js
"
;
export
enum
GEMINI_EMBEDDING_MODEL
{
EMBEDDING_001
=
"
embedding-001
"
,
TEXT_EMBEDDING_004
=
"
text-embedding-004
"
,
}
/**
/**
* GeminiEmbedding is an alias for Gemini that implements the BaseEmbedding interface.
* GeminiEmbedding is an alias for Gemini that implements the BaseEmbedding interface.
*/
*/
export
class
GeminiEmbedding
extends
BaseEmbedding
{
export
class
GeminiEmbedding
extends
BaseEmbedding
{
model
:
GEMINI_MODEL
;
model
:
GEMINI_EMBEDDING_MODEL
;
temperature
:
number
;
topP
:
number
;
maxTokens
?:
number
;
session
:
GeminiSession
;
session
:
GeminiSession
;
constructor
(
init
?:
GeminiConfig
)
{
constructor
(
init
?:
Partial
<
GeminiEmbedding
>
)
{
super
();
super
();
this
.
model
=
init
?.
model
??
GEMINI_MODEL
.
GEMINI_PRO
;
this
.
model
=
init
?.
model
??
GEMINI_EMBEDDING_MODEL
.
EMBEDDING_001
;
this
.
temperature
=
init
?.
temperature
??
0.1
;
this
.
topP
=
init
?.
topP
??
1
;
this
.
maxTokens
=
init
?.
maxTokens
??
undefined
;
this
.
session
=
init
?.
session
??
GeminiSessionStore
.
get
();
this
.
session
=
init
?.
session
??
GeminiSessionStore
.
get
();
}
}
...
...
This diff is collapsed.
Click to expand it.
packages/core/src/llm/gemini.ts
+
0
−
6
View file @
130b7992
...
@@ -32,8 +32,6 @@ type GeminiSessionOptions = {
...
@@ -32,8 +32,6 @@ type GeminiSessionOptions = {
export
enum
GEMINI_MODEL
{
export
enum
GEMINI_MODEL
{
GEMINI_PRO
=
"
gemini-pro
"
,
GEMINI_PRO
=
"
gemini-pro
"
,
GEMINI_PRO_VISION
=
"
gemini-pro-vision
"
,
GEMINI_PRO_VISION
=
"
gemini-pro-vision
"
,
EMBEDDING_001
=
"
embedding-001
"
,
AQA
=
"
aqa
"
,
GEMINI_PRO_LATEST
=
"
gemini-1.5-pro-latest
"
,
GEMINI_PRO_LATEST
=
"
gemini-1.5-pro-latest
"
,
}
}
...
@@ -44,16 +42,12 @@ export interface GeminiModelInfo {
...
@@ -44,16 +42,12 @@ export interface GeminiModelInfo {
export
const
GEMINI_MODEL_INFO_MAP
:
Record
<
GEMINI_MODEL
,
GeminiModelInfo
>
=
{
export
const
GEMINI_MODEL_INFO_MAP
:
Record
<
GEMINI_MODEL
,
GeminiModelInfo
>
=
{
[
GEMINI_MODEL
.
GEMINI_PRO
]:
{
contextWindow
:
30720
},
[
GEMINI_MODEL
.
GEMINI_PRO
]:
{
contextWindow
:
30720
},
[
GEMINI_MODEL
.
GEMINI_PRO_VISION
]:
{
contextWindow
:
12288
},
[
GEMINI_MODEL
.
GEMINI_PRO_VISION
]:
{
contextWindow
:
12288
},
[
GEMINI_MODEL
.
EMBEDDING_001
]:
{
contextWindow
:
2048
},
[
GEMINI_MODEL
.
AQA
]:
{
contextWindow
:
7168
},
[
GEMINI_MODEL
.
GEMINI_PRO_LATEST
]:
{
contextWindow
:
10
**
6
},
[
GEMINI_MODEL
.
GEMINI_PRO_LATEST
]:
{
contextWindow
:
10
**
6
},
};
};
const
SUPPORT_TOOL_CALL_MODELS
:
GEMINI_MODEL
[]
=
[
const
SUPPORT_TOOL_CALL_MODELS
:
GEMINI_MODEL
[]
=
[
GEMINI_MODEL
.
GEMINI_PRO
,
GEMINI_MODEL
.
GEMINI_PRO
,
GEMINI_MODEL
.
GEMINI_PRO_VISION
,
GEMINI_MODEL
.
GEMINI_PRO_VISION
,
GEMINI_MODEL
.
EMBEDDING_001
,
GEMINI_MODEL
.
AQA
,
];
];
const
DEFAULT_GEMINI_PARAMS
=
{
const
DEFAULT_GEMINI_PARAMS
=
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment