Skip to content

Commit

Permalink
Merge branch 'main' into feat/llm-config
Browse files Browse the repository at this point in the history
  • Loading branch information
tusharmath authored Aug 17, 2024
2 parents 2e4f922 + 1ff85a0 commit 9163f93
Show file tree
Hide file tree
Showing 111 changed files with 2,434 additions and 1,056 deletions.
20 changes: 10 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ indenter = "0.3.3"
derive_more = { workspace = true }
enum_dispatch = "0.3.13"
strum = "0.26.2"
maplit = "1.0.2"

[dev-dependencies]
tailcall-prettier = { path = "tailcall-prettier" }
Expand Down
2 changes: 1 addition & 1 deletion examples/grpc-reflection.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ input NewsInput {
}

type NewsData {
news: [News]!
news: [News]
}
2 changes: 1 addition & 1 deletion examples/grpc.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ input NewsInput {
}

type NewsData {
news: [News]!
news: [News]
}
2 changes: 1 addition & 1 deletion examples/telemetry-otlp.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,5 @@ enum Status {
}

type NewsData {
news: [News]!
news: [News]
}
6 changes: 3 additions & 3 deletions npm/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 14 additions & 14 deletions src/cli/llm/infer_type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ use std::collections::HashMap;

use genai::chat::{ChatMessage, ChatRequest, ChatResponse};
use serde::{Deserialize, Serialize};
use serde_json::json;

use super::{Error, Result, Wizard};
use crate::cli::generator::config::LLMConfig;
use crate::core::config::Config;
use crate::core::Mustache;

#[derive(Default)]
pub struct InferTypeName {
Expand Down Expand Up @@ -37,7 +39,6 @@ impl TryInto<ChatRequest> for Question {
type Error = Error;

fn try_into(self) -> Result<ChatRequest> {
let content = serde_json::to_string(&self)?;
let input = serde_json::to_string_pretty(&Question {
fields: vec![
("id".to_string(), "String".to_string()),
Expand All @@ -56,20 +57,19 @@ impl TryInto<ChatRequest> for Question {
],
})?;

let template_str = include_str!("prompts/infer_type_name.md");
let template = Mustache::parse(template_str).unwrap();

let context = json!({
"input": input,
"output": output,
});

let rendered_prompt = template.render(&context);

Ok(ChatRequest::new(vec![
ChatMessage::system(
"Given the sample schema of a GraphQL type suggest 5 meaningful names for it.",
),
ChatMessage::system("The name should be concise and preferably a single word"),
ChatMessage::system("Example Input:"),
ChatMessage::system(input),
ChatMessage::system("Example Output:"),
ChatMessage::system(output),
ChatMessage::system("Ensure the output is in valid JSON format".to_string()),
ChatMessage::system(
"Do not add any additional text before or after the json".to_string(),
),
ChatMessage::user(content),
ChatMessage::system(rendered_prompt),
ChatMessage::user(serde_json::to_string(&self)?),
]))
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/cli/llm/prompts/infer_type_name.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
Given the sample schema of a GraphQL type, suggest 5 meaningful names for it.
The name should be concise and preferably a single word.

Example Input:
{{input}}

Example Output:
{{output}}

Ensure the output is in valid JSON format.

Do not add any additional text before or after the JSON.
Original file line number Diff line number Diff line change
Expand Up @@ -8,56 +8,7 @@ ChatRequest {
ChatMessage {
role: System,
content: Text(
"Given the sample schema of a GraphQL type suggest 5 meaningful names for it.",
),
extra: None,
},
ChatMessage {
role: System,
content: Text(
"The name should be concise and preferably a single word",
),
extra: None,
},
ChatMessage {
role: System,
content: Text(
"Example Input:",
),
extra: None,
},
ChatMessage {
role: System,
content: Text(
"{\n \"fields\": [\n [\n \"id\",\n \"String\"\n ],\n [\n \"name\",\n \"String\"\n ],\n [\n \"age\",\n \"Int\"\n ]\n ]\n}",
),
extra: None,
},
ChatMessage {
role: System,
content: Text(
"Example Output:",
),
extra: None,
},
ChatMessage {
role: System,
content: Text(
"{\n \"suggestions\": [\n \"Person\",\n \"Profile\",\n \"Member\",\n \"Individual\",\n \"Contact\"\n ]\n}",
),
extra: None,
},
ChatMessage {
role: System,
content: Text(
"Ensure the output is in valid JSON format",
),
extra: None,
},
ChatMessage {
role: System,
content: Text(
"Do not add any additional text before or after the json",
"Given the sample schema of a GraphQL type, suggest 5 meaningful names for it.\nThe name should be concise and preferably a single word.\n\nExample Input:\n{\n \"fields\": [\n [\n \"id\",\n \"String\"\n ],\n [\n \"name\",\n \"String\"\n ],\n [\n \"age\",\n \"Int\"\n ]\n ]\n}\n\nExample Output:\n{\n \"suggestions\": [\n \"Person\",\n \"Profile\",\n \"Member\",\n \"Individual\",\n \"Contact\"\n ]\n}\n\nEnsure the output is in valid JSON format.\n\nDo not add any additional text before or after the JSON.\n",
),
extra: None,
},
Expand Down
5 changes: 4 additions & 1 deletion src/cli/telemetry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ use super::metrics::init_metrics;
use crate::cli::CLIError;
use crate::core::blueprint::telemetry::{OtlpExporter, Telemetry, TelemetryExporter};
use crate::core::runtime::TargetRuntime;
use crate::core::tracing::{default_tracing_tailcall, get_log_level, tailcall_filter_target};
use crate::core::tracing::{
default_tracing, default_tracing_tailcall, get_log_level, tailcall_filter_target,
};

static RESOURCE: Lazy<Resource> = Lazy::new(|| {
Resource::default().merge(&Resource::new(vec![
Expand Down Expand Up @@ -220,6 +222,7 @@ pub fn init_opentelemetry(config: Telemetry, runtime: &TargetRuntime) -> anyhow:

let subscriber = tracing_subscriber::registry()
.with(trace_layer)
.with(default_tracing())
.with(
log_layer.with_filter(dynamic_filter_fn(|_metatada, context| {
// ignore logs that are generated inside tracing::Span since they will be logged
Expand Down
60 changes: 60 additions & 0 deletions src/core/blueprint/fixture/all-constructs.graphql
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
schema
@server(port: 8000)
@upstream(baseURL: "http://jsonplaceholder.typicode.com", httpCache: 42, batch: {delay: 100}) {
query: Query
mutation: Mutation
}

enum Status {
ACTIVE
INACTIVE
PENDING
}

input UserInput {
name: String!
email: String!
status: Status
}

interface Node {
id: ID!
createdAt: DateTime!
updatedAt: DateTime!
}

type User implements Node {
id: ID!
name: String!
email: String!
status: Status
createdAt: DateTime!
updatedAt: DateTime!
}

union SearchResult = User | Post

type Post implements Node {
id: ID!
title: String!
content: String!
author: User!
createdAt: DateTime!
updatedAt: DateTime!
}

type Query {
user(id: ID!): User @http(path: "/users/{{.args.id}}")
search(term: String!): [SearchResult!] @http(path: "/search", query: [{key: "q", value: "{{.args.term}}"}])
}

input PostInput {
title: String!
content: String!
authorId: ID!
}

type Mutation {
createUser(input: UserInput!): User! @http(path: "/users", body: "{{.args.input}}", method: "POST")
createPost(input: PostInput): Post! @http(path: "/posts", body: "{{.args.input}}", method: "POST")
}
6 changes: 3 additions & 3 deletions src/core/blueprint/from_config.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{BTreeMap, BTreeSet, HashMap};
use std::collections::{BTreeMap, BTreeSet};

use async_graphql::dynamic::SchemaBuilder;

Expand Down Expand Up @@ -71,7 +71,7 @@ pub fn to_json_schema_for_field(field: &Field, config: &Config) -> JsonSchema {
to_json_schema(field, config)
}
pub fn to_json_schema_for_args(args: &BTreeMap<String, Arg>, config: &Config) -> JsonSchema {
let mut schema_fields = HashMap::new();
let mut schema_fields = BTreeMap::new();
for (name, arg) in args.iter() {
schema_fields.insert(name.clone(), to_json_schema(arg, config));
}
Expand All @@ -87,7 +87,7 @@ where
let type_ = config.find_type(type_of);
let type_enum_ = config.find_enum(type_of);
let schema = if let Some(type_) = type_ {
let mut schema_fields = HashMap::new();
let mut schema_fields = BTreeMap::new();
for (name, field) in type_.fields.iter() {
if field.resolver.is_none() {
schema_fields.insert(name.clone(), to_json_schema_for_field(field, config));
Expand Down
Loading

0 comments on commit 9163f93

Please sign in to comment.