Skip to content
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

feat(js): llama-index-ts llm support #829

Open
wants to merge 9 commits into
base: llama-index-ts
Choose a base branch
from

Conversation

cjunkin
Copy link
Contributor

@cjunkin cjunkin commented Aug 9, 2024

closes #615

const LLMMetadataAttr: Attributes = {};

LLMMetadataAttr[SemanticConventions.LLM_MODEL_NAME] = LLMObjectMetadata.model;
// TODO: How to prevent conflicts with input.additionalChatOptions?
Copy link
Contributor Author

@cjunkin cjunkin Aug 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah if you are accumulating attributes for a specific key (in this case invocation parameters) you probably need to change the structure a bit -

function getInvocationParams({stuffThatHasParams1, stuffThatHasParams2}) {
  const firstParams = someFunc(stuffThatHasParams1)
  const otherParams = someFunc2(stuffThatHasParams2)
  return safelyJSONStringify({...firstParams, ...otherParams})
}

This is just an exmple but something like this, unfortunately probably have to switch things up sinc eyou really only wanna stringify at the end once all are accumulated

@cjunkin cjunkin marked this pull request as ready for review August 12, 2024 20:38
@dosubot dosubot bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Aug 12, 2024

if (isLLMPrototype(prototype)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
this._wrap(prototype, "chat", (original): any => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is the return type any here just because the variations on the types of "chat" tha can come from the different classes?

Copy link
Contributor Author

@cjunkin cjunkin Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming you're referring to the "any" return type. The return type would be the function of (this: unknown, params: LLMChatParamsNonStreaming<object, object>) => Promise<ChatResponse<object>>. Should I assign this to a type variable and specify a strict return type here?

Comment on lines +366 to +369
// @ts-expect-error the response type is not correct - this is just for testing
async (): Promise<unknown> => {
return CHAT_RESPONSE;
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just curious is there a way to make it correct - totally fine to fallback to this if it's too much to fully mock, but if it's a fairly simple response we should try to get it right

Comment on lines +455 to +459
"Context information is below.\n" +
"---------------------\n" +
"lorem ipsum\n" +
"---------------------\n" +
"Given the context information and not prior knowledge, answer the query.\n" +
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for this portion of the query where does it come from? is this just injected from llama index? did you plug in a prompt template somewhere here? I see the document content and the query below bu curious about the rest

@dosubot dosubot bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Aug 14, 2024
setSpanAttributes({
span: span,
attributes: safelyGetDocumentAttributes(result),
});
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New way to set span attributes and check if safely... method returns null. Is this a good way to go about this?

@@ -50,7 +54,7 @@ export class LlamaIndexInstrumentation extends InstrumentationBase<
protected init(): InstrumentationModuleDefinition<typeof llamaindex> {
const module = new InstrumentationNodeModuleDefinition<typeof llamaindex>(
"llamaindex",
[">=0.1.0"],
[">=0.5.0"],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:XL This PR changes 500-999 lines, ignoring generated files.
Projects
Status: 📘 Todo
Development

Successfully merging this pull request may close these issues.

2 participants