mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-17 01:01:03 +02:00
Added Anthropic support and None logic
This commit is contained in:
parent
6cad3674c0
commit
75d0a90b4f
3 changed files with 40 additions and 6 deletions
|
|
@ -51,13 +51,17 @@ class Processor(Consumer):
|
|||
num_out = v.out_token
|
||||
|
||||
model_input_price, model_output_price = self.get_prices(price_list, modelname)
|
||||
cost_in = num_in * model_input_price
|
||||
cost_out = num_out * model_output_price
|
||||
cost_per_call = cost_in + cost_out
|
||||
|
||||
if model_input_price == None:
|
||||
cost_per_call = f"Model Not Found in Price list"
|
||||
else:
|
||||
cost_in = num_in * model_input_price
|
||||
cost_out = num_out * model_output_price
|
||||
cost_per_call = round(cost_in + cost_out, 6)
|
||||
|
||||
print(f"Input Tokens: {num_in}", flush=True)
|
||||
print(f"Output Tokens: {num_out}", flush=True)
|
||||
print(f"Cost for call: ${cost_per_call:.6f}", flush=True)
|
||||
print(f"Cost for call: ${cost_per_call}", flush=True)
|
||||
|
||||
@staticmethod
|
||||
def add_args(parser):
|
||||
|
|
|
|||
|
|
@ -44,6 +44,26 @@ price_list = {
|
|||
"model_name": "ollama",
|
||||
"input_price": 0,
|
||||
"output_price": 0
|
||||
}
|
||||
},
|
||||
{
|
||||
"model_name": "claude-3-haiku-20240307",
|
||||
"input_price": 0.00000025,
|
||||
"output_price": 0.00000125
|
||||
},
|
||||
{
|
||||
"model_name": "claude-3-5-sonnet-20240620",
|
||||
"input_price": 0.000003,
|
||||
"output_price": 0.000015
|
||||
},
|
||||
{
|
||||
"model_name": "claude-3-opus-20240229",
|
||||
"input_price": 0.000015,
|
||||
"output_price": 0.000075
|
||||
},
|
||||
{
|
||||
"model_name": "claude-3-sonnet-20240229",
|
||||
"input_price": 0.000003,
|
||||
"output_price": 0.000015
|
||||
},
|
||||
]
|
||||
}
|
||||
|
|
@ -105,10 +105,14 @@ class Processor(ConsumerProducer):
|
|||
)
|
||||
|
||||
resp = response.content[0].text
|
||||
inputtokens = response.usage.input_tokens
|
||||
outputtokens = response.usage.output_tokens
|
||||
print(resp, flush=True)
|
||||
print(f"Input Tokens: {inputtokens}", flush=True)
|
||||
print(f"Output Tokens: {outputtokens}", flush=True)
|
||||
|
||||
print("Send response...", flush=True)
|
||||
r = TextCompletionResponse(response=resp, error=None)
|
||||
r = TextCompletionResponse(response=resp, error=None, in_token=inputtokens, out_token=outputtokens, model=self.model)
|
||||
self.send(r, properties={"id": id})
|
||||
|
||||
print("Done.", flush=True)
|
||||
|
|
@ -125,6 +129,9 @@ class Processor(ConsumerProducer):
|
|||
message = str(e),
|
||||
),
|
||||
response=None,
|
||||
in_token=None,
|
||||
out_token=None,
|
||||
model=None,
|
||||
)
|
||||
|
||||
self.producer.send(r, properties={"id": id})
|
||||
|
|
@ -143,6 +150,9 @@ class Processor(ConsumerProducer):
|
|||
message = str(e),
|
||||
),
|
||||
response=None,
|
||||
in_token=None,
|
||||
out_token=None,
|
||||
model=None,
|
||||
)
|
||||
|
||||
self.producer.send(r, properties={"id": id})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue