Skip to content

Commit

Permalink
- Added create skill functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
roberthmoller committed Feb 19, 2024
1 parent ba7c3b8 commit 5290db2
Show file tree
Hide file tree
Showing 8 changed files with 104 additions and 66 deletions.
2 changes: 1 addition & 1 deletion functions/lib/api/skills/skill_router.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def list_skills(user: FirebaseUser = Depends(user_scope)) -> list[SavedSkillSpec
def create_skill(skill: SkillSpecification, user: FirebaseUser = Depends(user_scope)) -> SavedSkillSpecification:
print("Create skill: {0}".format(skill))
skill.name = skill.name.strip()
document = db().collection(f"v1/public/users/{user.uid}/agents").document()
document = db().collection(f"v1/public/users/{user.uid}/skills").document()
document.set(skill.model_dump())
return SavedSkillSpecification(id=document.id, **skill.model_dump())

Expand Down
3 changes: 2 additions & 1 deletion website/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
type RequestContext,
type ResponseContext,
server1,
SessionApi,
SessionApi, SkillsApi,
} from 'api-client';
import moment from "moment";

Expand Down Expand Up @@ -47,3 +47,4 @@ const config = createConfiguration(configurationParameters);
export const agentApi = new AgentApi(config);
export const authApi = new AuthApi(config);
export const sessionApi = new SessionApi(config);
export const skillsApi = new SkillsApi(config);
30 changes: 28 additions & 2 deletions website/src/lib/services/repositories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import {
AgentSpecification,
SavedAgentSpecification,
SavedMessageModel,
SavedSessionSpecification,
SessionSpecification
SavedSessionSpecification, SavedSkillSpecification,
SessionSpecification, SkillSpecification
} from "restClient";
import type {User} from "firebase/auth";
import {type Readable, type Writable, writable} from "svelte/store";
Expand Down Expand Up @@ -147,3 +147,29 @@ export class MessagesRepository extends Repository<SavedMessageModel, String> {
return message;
}
}

export class SkillRepository extends Repository<SavedSkillSpecification, SkillSpecification> {
readonly user: User;
readonly org: string;

constructor(user: User, org?: string) {
super();
this.user = user;
this.org = org ?? "public";
}

get collection(): string {
return `v1/${this.org}/users/${this.user.uid}/skills`;
}


factory(doc: DocumentData): SavedSkillSpecification {
const skill = new SavedSkillSpecification();
const data = doc.data();
skill.id = doc.id;
skill.name = data.name;
skill.requirements = data.requirements;
skill.code = data.code;
return skill;
}
}
41 changes: 35 additions & 6 deletions website/src/lib/services/workshop-service.ts
Original file line number Diff line number Diff line change
@@ -1,31 +1,60 @@
import {derived, get, readable, type Readable, type Writable, writable} from "svelte/store";
import {type SavedAgentSpecification} from "api-client";
import {type SavedAgentSpecification, SavedSkillSpecification, SkillSpecification} from "api-client";
import {authenticatedState} from "$lib/firebase";
import {AgentRepository} from "$lib/services/repositories";
import {AgentRepository, SkillRepository} from "$lib/services/repositories";
import type {ApiValue} from "$lib/services/util";
import {toast} from "svelte-sonner";
import type {User} from "firebase/auth";
import {skillsApi} from "$lib/api";


export enum WorkshopTab {
AGENTS, SKILLS, TASKS
}

class WorkshopState {
private user: User;
tabStore: Writable<WorkshopTab> = writable(WorkshopTab.AGENTS);
agentsStore: Readable<ApiValue<SavedAgentSpecification[]>>;
skillsStore: Readable<ApiValue<SavedSkillSpecification[]>>;


constructor(agents: Readable<ApiValue<SavedAgentSpecification[]>>) {
constructor(user: User, agents: Readable<ApiValue<SavedAgentSpecification[]>>, skills: Readable<ApiValue<SavedSkillSpecification[]>>) {
this.user = user;
this.agentsStore = agents;
this.skillsStore = skills
}


setTab(tab: WorkshopTab) {
this.tabStore.set(tab);
}


public async creteSkill(skill: SkillSpecification) {
console.log('create skill');
const promise = skillsApi.createSkillSkillsPost(skill);
toast.promise(
promise,
{
loading: "Creating skill...",
success: "Skill created!",
error: "Failed to create skill."
}
);
return await promise;
}
}

export const activeTab: Writable<WorkshopTab> = writable(WorkshopTab.AGENTS);
// export const agentsStore: Writable<ApiValue<SavedAgentSpecification[]>> = writable({value: [], isLoaded: false});
export const workshopStore: Readable<WorkshopState> = derived(
authenticatedState, (user) => {
const repository = new AgentRepository(user);
return new WorkshopState(
derived(repository.streamList(), (agents) => ({value: agents, isLoaded: true}))
const agents = new AgentRepository(user);
const skills = new SkillRepository(user);
return new WorkshopState(user,
derived(agents.streamList(), (agents) => ({value: agents, isLoaded: true})),
derived(skills.streamList(), (skills) => ({value: skills, isLoaded: true}))
);
}
);
Expand Down
36 changes: 11 additions & 25 deletions website/src/routes/(dashboard)/workshop/tabs/skills-tab.svelte
Original file line number Diff line number Diff line change
@@ -1,36 +1,22 @@
<script lang="ts">
// import {agentsStore, refreshAgents, workshopStore} from "$lib/services/workshop-service";
import CreateSkillCard from "./skills/create-skill-card.svelte";
import Editor from "./skills/editor.svelte";
// $: ({agentsStore} = $workshopStore);
// $: agents = $agentsStore;
import SkillCard from "./skills/skill-card.svelte";
import {workshopStore} from "$lib/services";
$: ({skillsStore} = $workshopStore);
$: skills = $skillsStore;
</script>

<h2 class="text-2xl font-semibold mb-2">Skills</h2>
<!--{#if agents.isLoaded ?? true }-->
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
<CreateSkillCard/>
<!--{#each agents.value as agent}-->
<!-- <AgentCard {agent}/>-->
<!--{/each}-->
<div class="w-[300px] h-[300px]">
<!-- <CodeMirror-->
<!-- value={code}-->
<!-- options={{-->
<!-- mode: 'python',-->
<!-- theme: 'vscode-dark',-->
<!-- lineNumbers: true,-->
<!-- }}-->
<!-- />-->
<Editor/>

<!-- lang={python()}-->
<!-- theme={vscodeDark}-->
<!-- class="h-[10rem] w-[20rem]"-->
</div>
<div class="grid gap-4 md:grid-cols-2 lg:grid-cols-4">
<CreateSkillCard/>
{#each skills.value as skill}
<SkillCard {skill}/>
{/each}

</div>
</div>
<!--{:else if agents.error}-->
<!-- <div class="flex h-[450px] shrink-0 items-center justify-center">-->
<!-- <div class="mx-auto flex max-w-[420px] flex-col items-center justify-center text-center">-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,41 +3,27 @@
import {Button} from "$lib/components/ui/button";
import {Label} from "$lib/components/ui/label";
import {Input} from "$lib/components/ui/input";
import {PipRequirement, SkillSpecification} from "restClient";
import Editor from "./editor.svelte"
import {SkillSpecification} from "restClient";
let open = false;
let name = "";
let requirement: PipRequirement[] = [];
let code = "import autogen";
import {workshopStore} from "$lib/services";
async function createSkill() {
let skill = new SkillSpecification();
skill.name = name;
skill.requirements = requirement;
skill.code = code;
$: ({creteSkill} = $workshopStore);
let open = false;
let skill = new SkillSpecification();
try {
// toast.promise(
// agentApi.createAgentAgentsPost(null), {
// loading: "Creating agent...",
// success: "Agent created successfully",
// error: "Failed to create agent",
// description: "This might take some seconds. Please wait..."
// }
// );
open = false;
} catch (e: any) {
console.error("Error creating skill: ", e);
}
const createAndClose = () => {
skill.requirements = [{name: "pip", version: "20.3.4"}]
creteSkill(skill);
open = false;
}
</script>

<Dialog.Root bind:open>
<Dialog.Trigger asChild let:builder>
<Button size="sm" builders={[builder]} class="relative">Create</Button>
</Dialog.Trigger>
<Dialog.Content>
<Dialog.Content class="sm:max-w-[1000px]">
<Dialog.Header>
<Dialog.Title>Create an agent</Dialog.Title>
<Dialog.Description>Define a new agent and its capabilities.</Dialog.Description>
Expand All @@ -52,27 +38,27 @@
type="text"
autocapitalize="words"
autocorrect="off"
bind:value={name}
bind:value={skill.name}
/>
</div>
<div class="grid gap-2">
<Label for="url">Requirements</Label>
<!-- Todo: Make a select box where you can delete/add reqs and change their version-->
<!-- Todo: Make a select box where you can delete/add reqs and change their version-->
<Input
id="requirements"
placeholder="A list of requirements that the skill needs to be able to run. E.g. pip install wikipedia."
autocorrect="on"
bind:value={requirement}
bind:value={skill.requirements}
/>
</div>
<div class=" h-[25rem] flex space-y-2 flex-col">
<Label for="code">Code</Label>
<Editor bind:code={code} class="flex-grow h-100 justify-stretch flex overflow-y-scroll"/>
<Editor bind:code={skill.code} class="flex-grow h-100 justify-stretch flex overflow-y-scroll"/>
</div>
</div>
</form>
<Dialog.Footer>
<Button on:click={createSkill}>Create</Button>
<Button on:click={createAndClose}>Create</Button>
</Dialog.Footer>
</Dialog.Content>
</Dialog.Root>
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<script lang="ts">
import {onMount} from 'svelte';
import {EditorState} from '@codemirror/state';
import {EditorView, lineNumbers, keymap, hasHoverTooltips} from '@codemirror/view';
import {EditorView, lineNumbers, keymap} from '@codemirror/view';
import {defaultKeymap} from '@codemirror/commands';
import {python, pythonLanguage} from '@codemirror/lang-python';
import {python} from '@codemirror/lang-python';
import {oneDark} from '@codemirror/theme-one-dark';
import {autocompletion, completionKeymap} from '@codemirror/autocomplete';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

<script lang="ts">
import {SavedSkillSpecification} from "restClient";
export let skill: SavedSkillSpecification;
</script>

<div>
{skill.name}
</div>

0 comments on commit 5290db2

Please sign in to comment.