update cache and parsing algorithm
Some checks failed
Code Review / review (pull_request) Failing after 11s
Some checks failed
Code Review / review (pull_request) Failing after 11s
This commit is contained in:
13
.github/scripts/code_review.py
vendored
13
.github/scripts/code_review.py
vendored
@@ -3,9 +3,11 @@ import os
|
||||
import re
|
||||
import fnmatch
|
||||
import json
|
||||
import datetime
|
||||
from openai import OpenAI
|
||||
from anthropic import Anthropic
|
||||
import google.generativeai as genai
|
||||
from google.generativeai import caching
|
||||
from collections import defaultdict
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from typing import Any, Optional, Callable
|
||||
@@ -134,10 +136,17 @@ def parse_provider(
|
||||
)
|
||||
elif any(key in model for key in ["gemini"]):
|
||||
genai.configure(api_key=GOOGLE_API_KEY)
|
||||
gemini = genai.GenerativeModel(model, system_instruction=system_prompt)
|
||||
cache = caching.CachedContent.create(
|
||||
model=f"models/{model}",
|
||||
display_name="Gitea Code Reviewer", # used to identify the cache
|
||||
system_instruction=system_prompt,
|
||||
contents=[],
|
||||
ttl=datetime.timedelta(minutes=5),
|
||||
)
|
||||
gemini = genai.GenerativeModel.from_cached_content(cached_content=cache)
|
||||
return (
|
||||
lambda prompt: gemini.generate_content(prompt),
|
||||
lambda response: response.text.strip() or "[]",
|
||||
lambda response: response.text.strip("`").lstrip("json").strip() or "[]",
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Invalid model: {model}")
|
||||
|
||||
Reference in New Issue
Block a user