mirror of
https://github.com/technovangelist/videoprojects.git
synced 2026-09-10 07:16:19 -04:00
add feb 22
Signed-off-by: Matt Williams <m@technovangelist.com>
This commit is contained in:
parent
f7b91d91a6
commit
ee02d4318f
15
2024-02-22 embeddings/README.md
Normal file
15
2024-02-22 embeddings/README.md
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
# embeddings
|
||||
|
||||
To install dependencies:
|
||||
|
||||
```bash
|
||||
bun install
|
||||
```
|
||||
|
||||
To run:
|
||||
|
||||
```bash
|
||||
bun run embed.ts
|
||||
```
|
||||
|
||||
This project was created using `bun init` in bun v1.0.25. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.
|
||||
BIN
2024-02-22 embeddings/bun.lockb
Executable file
BIN
2024-02-22 embeddings/bun.lockb
Executable file
Binary file not shown.
32
2024-02-22 embeddings/embed.py
Normal file
32
2024-02-22 embeddings/embed.py
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
import ollama
|
||||
|
||||
def read_file(file_path):
|
||||
with open(file_path, 'r') as file:
|
||||
return file.read()
|
||||
|
||||
|
||||
def split_into_chunks(text, chunk_size):
|
||||
words = text.split()
|
||||
chunks = []
|
||||
current_chunk = []
|
||||
|
||||
for word in words:
|
||||
current_chunk.append(word)
|
||||
if len(current_chunk) >= chunk_size:
|
||||
chunks.append(' '.join(current_chunk))
|
||||
current_chunk = []
|
||||
|
||||
if current_chunk:
|
||||
chunks.append(' '.join(current_chunk))
|
||||
|
||||
return chunks
|
||||
|
||||
file_path = '/Users/matt/Downloads/warandpeace.txt' #
|
||||
long_string = read_file(file_path)
|
||||
chunk_size = 500
|
||||
chunks = split_into_chunks(long_string, chunk_size)
|
||||
|
||||
for i, chunk in enumerate(chunks, start=1):
|
||||
response = ollama.embeddings(model='nomic-embed-text', prompt=chunk)
|
||||
print(i)
|
||||
|
||||
41
2024-02-22 embeddings/embed.ts
Normal file
41
2024-02-22 embeddings/embed.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
|
||||
import { Ollama } from "ollama";
|
||||
|
||||
const ollama = new Ollama();
|
||||
|
||||
function splitIntoChunks(text: string, chunkSize: number): string[] {
|
||||
const words: string[] = text.split(/\s+/);
|
||||
const chunks: string[] = [];
|
||||
let currentChunk: string[] = [];
|
||||
|
||||
for (const word of words) {
|
||||
currentChunk.push(word);
|
||||
if (currentChunk.length >= chunkSize) {
|
||||
chunks.push(currentChunk.join(' '));
|
||||
currentChunk = [];
|
||||
}
|
||||
}
|
||||
if (currentChunk.length > 0) {
|
||||
chunks.push(currentChunk.join(' '));
|
||||
}
|
||||
return chunks;
|
||||
}
|
||||
|
||||
|
||||
const path = "/Users/matt/Downloads/warandpeace.txt";
|
||||
const file = Bun.file(path);
|
||||
|
||||
const chunks = splitIntoChunks(await file.text(), 500);
|
||||
console.log('done reading')
|
||||
|
||||
|
||||
let i = 0
|
||||
for await (const c of chunks) {
|
||||
i++;
|
||||
const b = await ollama.embeddings({
|
||||
model: "llama2",
|
||||
prompt: c
|
||||
})
|
||||
console.log(i);
|
||||
}
|
||||
|
||||
14
2024-02-22 embeddings/package.json
Normal file
14
2024-02-22 embeddings/package.json
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
{
|
||||
"name": "embeddings",
|
||||
"module": "embed.ts",
|
||||
"type": "module",
|
||||
"devDependencies": {
|
||||
"@types/bun": "latest"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"typescript": "^5.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"ollama": "^0.4.6"
|
||||
}
|
||||
}
|
||||
5
2024-02-22 embeddings/simple.py
Normal file
5
2024-02-22 embeddings/simple.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
import ollama
|
||||
|
||||
out = ollama.embeddings(model="nomic-embed-text", prompt="hi hi")
|
||||
|
||||
print(out)
|
||||
4
2024-02-22 embeddings/test.http
Normal file
4
2024-02-22 embeddings/test.http
Normal file
File diff suppressed because one or more lines are too long
10
2024-02-22 embeddings/test.py
Normal file
10
2024-02-22 embeddings/test.py
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
import ollama
|
||||
|
||||
stream = ollama.chat(
|
||||
model='mistral',
|
||||
messages=[{'role': 'user', 'content': 'Why is the sky blue?'}],
|
||||
stream=True,
|
||||
)
|
||||
|
||||
for chunk in stream:
|
||||
print(chunk['message']['content'], end='', flush=True)
|
||||
22
2024-02-22 embeddings/tsconfig.json
Normal file
22
2024-02-22 embeddings/tsconfig.json
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
{
|
||||
"compilerOptions": {
|
||||
"lib": ["ESNext"],
|
||||
"target": "ESNext",
|
||||
"module": "ESNext",
|
||||
"moduleDetection": "force",
|
||||
"jsx": "react-jsx",
|
||||
"allowJs": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"skipLibCheck": true,
|
||||
"strict": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"forceConsistentCasingInFileNames": true
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue