Skip to content
This repository has been archived by the owner on Apr 29, 2024. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'pair-recommendation-rudders/master' int…
Browse files Browse the repository at this point in the history
…o try-merge-pair-master-into-lsir-repo
  • Loading branch information
LeoLaugier committed Apr 2, 2024
2 parents faab3fa + 27e071c commit be8615f
Show file tree
Hide file tree
Showing 31 changed files with 894 additions and 48 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,3 +47,5 @@ testem.log
.DS_Store
Thumbs.db
17.0.6/*

llm-recs/*
4 changes: 2 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true
},
"[typescript]": {
"editor.defaultFormatter": "dbaeumer.vscode-eslint",
"editor.codeActionsOnSave": {
"source.fixAll.eslint": true
"source.fixAll.eslint": "explicit"
},
"editor.formatOnSave": true
},
Expand Down
5 changes: 5 additions & 0 deletions src/app/app-routing.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { ExperimentSettingsComponent } from './experimenter-view/experiment-sett
import { experimenterAuthGuard } from './experimenter-auth.guard';
import { validParticipantGuard } from './valid-participant.guard';
import { CreateExperimentComponent } from './experimenter-view/create-experiment/create-experiment.component';
import { LlmApiConfigComponent } from './experimenter-view/llm-api-config/llm-api-config.component';

const routes: Routes = [
{
Expand Down Expand Up @@ -54,6 +55,10 @@ const routes: Routes = [
component: AppSettingsComponent,
pathMatch: 'full',
},
{ path: 'llm-settings',
component: LlmApiConfigComponent,
pathMatch: 'full',
},
],
},
{ path: '', component: AppHomeComponent, pathMatch: 'full' },
Expand Down
2 changes: 2 additions & 0 deletions src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { ExpTosAndProfileComponent } from './participant-view/participant-stage-
import { ExpTosComponent } from './participant-view/participant-stage-view/exp-tos/exp-tos.component';
import { GoogleAuthService } from './services/google-auth.service';
import { GoogleSheetsService } from './services/google-sheets.service';
import { LlmApiConfigComponent } from './experimenter-view/llm-api-config/llm-api-config.component';
import { LmApiService } from './services/lm-api.service';
import { MatBadgeModule } from '@angular/material/badge';
import { MatButtonModule } from '@angular/material/button';
Expand Down Expand Up @@ -77,6 +78,7 @@ import { ExperimenterViewComponent } from './experimenter-view/experimenter-view
CodemirrorConfigEditorModule,
AppHomeComponent,
AppSettingsComponent,
LlmApiConfigComponent,
ExpSurveyComponent,
ExpLeaderVoteComponent,
ExpProfileComponent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,9 @@ <h2>Experiment stages:</h2>
}
</div>
}

<h2>Experiment settings:</h2>

<button mat-raised-button color="warn" aria-label="Delete" (click)="deleteExperiment()">
<mat-icon>delete</mat-icon> Delete this experiment
</button>
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import { Component, Input, Signal, WritableSignal, computed, signal } from '@angular/core';
import { RouterLink, RouterLinkActive, RouterModule } from '@angular/router';
import { Router, RouterLink, RouterLinkActive, RouterModule } from '@angular/router';
import { AppStateService } from 'src/app/services/app-state.service';
import { deleteExperiment } from 'src/lib/staged-exp/app';
import { MatExpansionModule } from '@angular/material/expansion';
import { MatButtonModule } from '@angular/material/button';
import { MatIconModule } from '@angular/material/icon';

import { StageKinds, UserData, UserProfile } from 'src/lib/staged-exp/data-model';
import { MediatorChatComponent } from '../mediator-chat/mediator-chat.component';
Expand All @@ -18,7 +21,7 @@ export interface StageState {
@Component({
selector: 'app-experiment-monitor',
standalone: true,
imports: [RouterModule, RouterLink, RouterLinkActive, MediatorChatComponent, MatExpansionModule],
imports: [RouterModule, RouterLink, RouterLinkActive, MediatorChatComponent, MatButtonModule, MatExpansionModule, MatIconModule],
templateUrl: './experiment-monitor.component.html',
styleUrl: './experiment-monitor.component.scss',
})
Expand All @@ -37,7 +40,7 @@ export class ExperimentMonitorComponent {
isOfKind = isOfKind;
readonly StageKinds = StageKinds;

constructor(public stateService: AppStateService) {
constructor(public stateService: AppStateService, public router: Router) {
this.participants = computed(() => {
console.log('experimentName:', this.experimentName());
if (!(this.experimentName() in this.stateService.data().experiments)) {
Expand Down Expand Up @@ -74,4 +77,15 @@ export class ExperimentMonitorComponent {
return stageStates;
});
}

deleteExperiment() {
if (confirm("⚠️ This will delete the experiment! Are you sure?")) {
this.stateService.editData((data) =>
deleteExperiment(this.experimentName(), data),
);

// Redirect to settings page.
this.router.navigate(['/experimenter', 'settings']);
}
}
}
8 changes: 8 additions & 0 deletions src/app/experimenter-view/experimenter-view.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,14 @@
>
<mat-icon fontIcon="settings"></mat-icon> Settings
</mat-list-item>
<mat-list-item
matListItemTitle
[routerLink]="['llm-settings']"
ariaCurrentWhenActive="page"
class="menu-item"
>
<mat-icon fontIcon="settings"></mat-icon> LLM Settings
</mat-list-item>
</mat-nav-list>
</mat-sidenav>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="main">

<p>
You can this on the command line to get your parameters:
</p>
<pre>
echo "Project: $(gcloud config get-value project)"
echo "AccessToken: $(gcloud auth print-access-token)"
</pre>
<p>
Note: the access token generally works for <b>1 hour</b>. After that, you'll need to
renew it.
</p>
<p>
And then copy/paste them here:
</p>
<form class="cloud-info-form">
<mat-form-field class="full-width" >
<mat-label>Project</mat-label>
<input type="text" matInput [formControl]="projectControl">
</mat-form-field>

<mat-form-field class="full-width">
<mat-label>AccessToken</mat-label>
<textarea matInput [formControl]="tokenControl"></textarea>
</mat-form-field>
</form>
<p>
These values are saved in your local browser storage, you can clear them
by simply editing the above fields (local browser storage is updated as you
type).
</p>
</div>

<button color="primary" mat-button (click)="sendRequest()">
<span>Send</span>
</button>
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
.cloud-info-form {
min-width: 150px;
max-width: 500px;
width: 100%;
}

.full-width {
width: 100%;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { ComponentFixture, TestBed } from '@angular/core/testing';

import { LlmApiConfigComponent } from './llm-api-config.component';

describe('LlmApiConfigComponent', () => {
let component: LlmApiConfigComponent;
let fixture: ComponentFixture<LlmApiConfigComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [LlmApiConfigComponent]
})
.compileComponents();

fixture = TestBed.createComponent(LlmApiConfigComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an Apache2 license that can be
* found in the LICENSE file and http://www.apache.org/licenses/LICENSE-2.0
==============================================================================*/

import { Component, effect } from '@angular/core';
import { FormControl } from '@angular/forms';
import { VertexApiService } from '../../services/vertex-api.service';
import { MatInputModule } from '@angular/material/input';
import { MatFormFieldModule } from '@angular/material/form-field';
import { ReactiveFormsModule } from '@angular/forms';
import { preparePalm2Request, sendPalm2Request } from 'src/lib/text-templates/llm_vertexapi_palm2';

@Component({
selector: 'app-llm-api-config',
templateUrl: './llm-api-config.component.html',
styleUrls: ['./llm-api-config.component.scss'],
standalone: true,
imports: [MatFormFieldModule, MatInputModule, ReactiveFormsModule],
})
export class LlmApiConfigComponent {
public tokenControl: FormControl<string | null>;
public projectControl: FormControl<string | null>;

constructor(private llmService: VertexApiService) {
this.tokenControl = new FormControl<string | null>(this.llmService.accessToken);
this.projectControl = new FormControl<string | null>(this.llmService.projectId);

this.tokenControl.valueChanges.forEach(update => {
if (update && this.llmService.accessToken !== update) {
this.llmService.accessToken = update
}
});
this.projectControl.valueChanges.forEach(update => {
if (update && this.llmService.projectId !== update) {
this.llmService.projectId = update
}
});
}
// The Token is valid for 1 hour! Don't forget to renew it!
async sendRequest() {
const prompt = `Hello word`;
const request = preparePalm2Request(prompt);
console.log(JSON.stringify(request));
console.log(this.llmService.projectId);
console.log(this.llmService.accessToken);
const response = await sendPalm2Request(
this.llmService.projectId, this.llmService.accessToken, request);
console.log(JSON.stringify(response));
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
} @else if (message.messageType === 'mediatorMessage') {
<app-chat-mediator-message [message]="message"></app-chat-mediator-message>
} @else if (message.messageType === 'discussItemsMessage') {
<app-chat-discuss-items-message></app-chat-discuss-items-message>
<app-chat-discuss-items-message [discussItemsMessage]="message"></app-chat-discuss-items-message>
} @else {
<div></div>
}
Expand All @@ -17,6 +17,59 @@
</div>

<div class="message-form">
<h4> Select a pair of item to send to the chat participants </h4>

@if (itemPair().item1 == itemPair().item2){
<div class="error-message">
Please select two different items
</div>
}
<!-- select pair of items -->
<mat-form-field>
<mat-label>Item 1</mat-label>
<mat-select [(value)]="itemPair().item1" (selectionChange)="updateItemPair($event, 1)" required>
@for (item of items(); track item) {
<!-- @if (item != itemPair().item2){ -->
<mat-option [value]="item">
<div class="item-pair">
<img src="{{item.imageUrl}}" alt="{{item.name}}" width="20px" /> {{item.name}}
</div>
</mat-option>
<!-- } -->
}
</mat-select>
</mat-form-field>

<mat-form-field>
<mat-label>Item 2</mat-label>
<mat-select [(value)]="itemPair().item2" (selectionChange)="updateItemPair($event, 2)" required>
@for (item of items(); track item) {
<!-- @if (item != itemPair().item1){ -->
<mat-option [value]="item">
<div class="item-pair">
<img src="{{item.imageUrl}}" alt="{{item.name}}" width="20px" /> {{item.name}}
</div>
</mat-option>
<!-- } -->
}
</mat-select>
</mat-form-field>


<mat-form-field class="full-width">
<mat-label>Instructions to send</mat-label>
<input matInput placeholder="Write your response" [(ngModel)]="instructions" />
</mat-form-field>


<button color="primary" mat-button (click)="sendRatingToDiscuss()" [disabled]="itemPair().item1 == itemPair().item2">
<!-- <mat-icon>redo</mat-icon> -->
<span>Send</span>
</button>
</div>

<div class="message-form">
<h4> Send any message to the chat </h4>
<mat-form-field class="full-width">
<mat-label>Message to send</mat-label>
<input matInput placeholder="Write your response" [(ngModel)]="message" />
Expand All @@ -26,3 +79,30 @@
<span>Send</span>
</button>
</div>

<div>
<h4> Send automatic mediating intervention to the chat.
The prompt will be made of:
<ol>
<li>
<b>A prefix</b> - default: {{this.defaultPrefix}}
</li>
<li>
<b>The current discussion</b> - e.g.: <br>Username: "John Doe"<br> Message: "I think..."
</li>
<li>
<b>A suffix</b> - default: {{this.defaultSuffix}}
</ol>
</h4>
<mat-form-field class="full-width">
<mat-label>Write a custom prefix</mat-label>
<input matInput placeholder="Write your prefix" [(ngModel)]="prefix" />
</mat-form-field>
<mat-form-field class="full-width">
<mat-label>Write a custom suffix</mat-label>
<input matInput placeholder="Write your suffix" [(ngModel)]="suffix" />
</mat-form-field>
<button color="primary" mat-button (click)="sendLLMMessage()">
<span>Send</span>
</button>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.item-pair{
display: flex;
justify-content: space-between;
}

.error-message{
color: red;
font-size: 12px;
margin-top: 5px;
}
Loading

0 comments on commit be8615f

Please sign in to comment.