-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Morph updates #5918
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Morph updates #5918
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Chunk, LLMOptions } from "../../index.js"; | ||
import OpenAI from "./OpenAI.js"; | ||
|
||
class Morph extends OpenAI { | ||
static providerName = "morph"; | ||
static defaultOptions: Partial<LLMOptions> = { | ||
apiBase: "https://api.morphllm.com/v1", | ||
maxEmbeddingBatchSize: 96, | ||
}; | ||
static maxStopSequences = 5; | ||
|
||
async rerank(query: string, chunks: Chunk[]): Promise<number[]> { | ||
const resp = await this.fetch(new URL("rerank", this.apiBase), { | ||
method: "POST", | ||
headers: { | ||
Authorization: `Bearer ${this.apiKey}`, | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
model: this.model, | ||
query, | ||
documents: chunks.map((chunk) => chunk.content), | ||
}), | ||
}); | ||
|
||
if (!resp.ok) { | ||
throw new Error(await resp.text()); | ||
} | ||
|
||
const data = (await resp.json()) as any; | ||
const results = data.results.sort((a: any, b: any) => a.index - b.index); | ||
return results.map((result: any) => result.relevance_score); | ||
} | ||
} | ||
export default Morph; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import BedrockImport from "./BedrockImport"; | |
import Cerebras from "./Cerebras"; | ||
import Cloudflare from "./Cloudflare"; | ||
import Cohere from "./Cohere"; | ||
import Morph from "./Morph" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code attempts to import a non-existent module './Morph'. The Morph.ts file does not exist in the core/llm/llms directory. This will cause a runtime error when the module tries to load, as Node.js/TypeScript will fail to resolve the import. The module must be created before it can be imported.
|
||
import DeepInfra from "./DeepInfra"; | ||
import Deepseek from "./Deepseek"; | ||
import Docker from "./Docker"; | ||
|
@@ -116,6 +117,7 @@ export const LLMClasses = [ | |
SiliconFlow, | ||
Scaleway, | ||
Relace, | ||
Morph, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding the non-existent Morph class to LLMClasses array will cause a runtime error. The Morph class is undefined since its module doesn't exist, and this will cause a runtime error when the array is used in llmFromDescription or llmFromProviderAndOptions functions. The Morph implementation must be created and properly implement the ILLM interface before being added to LLMClasses.
|
||
Inception, | ||
Voyage, | ||
]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { ModelProvider } from "../types.js"; | ||
|
||
export const Morph: ModelProvider = { | ||
models: [ | ||
{ | ||
model: "morph-rerank-v2", | ||
displayName: "Morph Rerank v2", | ||
// contextLength: 128000, | ||
// maxCompletionTokens: 4000, | ||
// recommendedFor: ["rerank"], | ||
}, | ||
{ | ||
model: "morph-v2", | ||
displayName: "Morph Fast Apply v2", | ||
// contextLength: 128000, | ||
// maxCompletionTokens: 4000, | ||
}, | ||
{ | ||
model: "morph-embedding-v2", | ||
displayName: "Morph Embedding v2", | ||
// recommendedFor: ["embed"], | ||
// contextLength: 512, | ||
}, | ||
], | ||
id: "morph", | ||
displayName: "Morph", | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code assumes data.results exists and is an array without validation. If the API response doesn't include a 'results' property or if it's not an array, this will cause a runtime error. Additionally, using 'any' type for sort parameters loses type safety. The code should validate the response structure and use proper typing.