Skip to content

Add usage to VertexAI LLMResponse #408

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/neo4j_graphrag/llm/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ def __getattr__(name: str) -> Any:
raise AttributeError(f"module {__name__!r} has no attribute {name!r}")


class LLMUsage(BaseModel):
prompt_token_count: int
candidates_token_count: int
thoughts_token_count: int
total_token_count: int


class LLMResponse(BaseModel):
content: str
usage: Optional[LLMUsage] = None


class BaseMessage(BaseModel):
Expand Down
7 changes: 7 additions & 0 deletions src/neo4j_graphrag/llm/vertexai_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
MessageList,
ToolCall,
ToolCallResponse,
LLMUsage,
)
from neo4j_graphrag.message_history import MessageHistory
from neo4j_graphrag.tool import Tool
Expand Down Expand Up @@ -285,6 +286,12 @@ def _parse_tool_response(self, response: GenerationResponse) -> ToolCallResponse
def _parse_content_response(self, response: GenerationResponse) -> LLMResponse:
return LLMResponse(
content=response.text,
usage=LLMUsage(
prompt_token_count=response.usage_metadata.prompt_token_count,
candidates_token_count=response.usage_metadata.candidates_token_count,
total_token_count=response.usage_metadata.total_token_count,
thoughts_token_count=response.usage_metadata.thoughts_token_count,
),
)

async def ainvoke_with_tools(
Expand Down
Loading