(misc) clickhouse cookbook

This commit is contained in:
ishaan-jaff 2024-02-26 07:37:44 -08:00
parent bd5d447231
commit 78c847ec5e

View file

@ -1,55 +1,53 @@
import clickhouse_connect import clickhouse_connect
import datetime as datetime
import os
# client = clickhouse_connect.get_client( client = clickhouse_connect.get_client(
# host='hjs1z7j37j.us-east1.gcp.clickhouse.cloud', host=os.getenv("CLICKHOUSE_HOST"),
# port=8443, port=int(os.getenv("CLICKHOUSE_PORT")),
# username='default', username=os.getenv("CLICKHOUSE_USERNAME"),
# password='M~PimRs~c3Z6b', password=os.getenv("CLICKHOUSE_PASSWORD"),
# secure=False )
# )
import clickhouse_connect import clickhouse_connect
client = clickhouse_connect.get_client()
row1 = [ row1 = [
"123456", # request_id "ishaan", # request_id
"GET", # call_type "GET", # call_type
"api_key_123", # api_key "api_key_123", # api_key
50.00, # spend 50.00, # spend
1000, # total_tokens 1000, # total_tokens
800, # prompt_tokens 800, # prompt_tokens
200, # completion_tokens 200, # completion_tokens
"2024-02-24 12:00", # startTime (replace with the actual timestamp) datetime.datetime.now(), # startTime (replace with the actual timestamp)
"2024-02-24 13:00", # endTime (replace with the actual timestamp) datetime.datetime.now(), # endTime (replace with the actual timestamp)
"gpt-3.5", # model "gpt-3.5", # model
"user123", # user "user123", # user
'{"key": "value"}', # metadata (replace with valid JSON) '{"key": "value"}', # metadata (replace with valid JSON)
True, # cache_hit "True", # cache_hit
"cache_key_123", # cache_key "cache_key_123", # cache_key
"tag1,tag2", # request_tags "tag1,tag2", # request_tags
] ]
row2 = [ row2 = [
"789012", # request_id "jaffer", # request_id
"POST", # call_type "POST", # call_type
"api_key_456", # api_key "api_key_456", # api_key
30.50, # spend 30.50, # spend
800, # total_tokens 800, # total_tokens
600, # prompt_tokens 600, # prompt_tokens
200, # completion_tokens 200, # completion_tokens
"2024-02-24 14:00", # startTime (replace with the actual timestamp) datetime.datetime.now(), # startTime (replace with the actual timestamp)
"2024-02-24 15:00", # endTime (replace with the actual timestamp) datetime.datetime.now(), # endTime (replace with the actual timestamp)
"gpt-4.0", # model "gpt-4.0", # model
"user456", # user "user456", # user
'{"key": "value"}', # metadata (replace with valid JSON) '{"key": "value"}', # metadata (replace with valid JSON)
False, # cache_hit "False", # cache_hit
"cache_key_789", # cache_key "cache_key_789", # cache_key
"tag3,tag4", # request_tags "tag3,tag4", # request_tags
] ]
data = [row1, row2] data = [row1, row2]
client.insert( resp = client.insert(
"spend_logs", "spend_logs",
data, data,
column_names=[ column_names=[
@ -70,3 +68,5 @@ client.insert(
"request_tags", "request_tags",
], ],
) )
print(resp)