Skip to content

Instantly share code, notes, and snippets.

View GuillaumeDaviid's full-sized avatar

Guillaume DAVID GuillaumeDaviid

View GitHub Profile
:nth-child(An+B [of S]?)
:nth-last-child(An+B [of S]?)
:nth-child(2n)
:nth-child(2n+1)
.nesting {
color: hotpink;
> .is {
color: rebeccapurple;
> .awesome {
color: deeppink;
}
}
.nesting {
color: hotpink;
}
.nesting > .is {
color: rebeccapurple;
}
.nesting > .is > .awesome {
color: deeppink;
<div>
<h1 class="title">Chat Bot with GPT</h1>
<div class="chat_bot" id="chat_bot">
<div class="chat_bot_content-msg" id="chat_bot_content-msg">
<h2 class="chat_bot-msg">Bot :</h2>
<p class="chat_bot-msg" *ngIf="botResponse">{{botResponse}}</p>
<p class="chat_bot-msg" *ngIf="!botResponse">Bonjour, Je suis un bot codé en Angular et utilisant GPT3 d'Open AI</p>
</div>
</div>
<form class="form">
@GuillaumeDaviid
GuillaumeDaviid / gist:e210cb47fe4883e41647cbaac1696a6b
Created October 13, 2023 09:24
Angular IA, chat composant ts
import { Component } from '@angular/core';
import { OpenAiService } from '../open-ai.service'
@Component({
selector: 'app-chat',
templateUrl: './chat.component.html',
styleUrls: ['./chat.component.scss']
})
export class ChatComponent {
newMsg: string = '';
handleClick() {
this.openAiService.getDataFromOpenAI(this.newMsg).subscribe(data => {
this.botResponse = data;
});
this.newMsg = '';
}
@GuillaumeDaviid
GuillaumeDaviid / gist:68c78f03da8d4f2a327473c1cbe063ad
Last active October 13, 2023 09:02
angular, import service openAI
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
import { OpenAiService } from '../open-ai.service'
@Component({
selector: 'app-chat',
templateUrl: './chat.component.html',
styleUrls: ['./chat.component.scss']
})
export class ChatComponent {
getDataFromOpenAI(text: string): Observable<string> {
return from(this.openai.createCompletion({
model: "text-davinci-003",
prompt: text,
max_tokens: 7
})).pipe(
filter(resp => !!resp && !!resp.data),
map(resp => resp.data),
filter((data: any) => data.choices && data.choices.length > 0 && data.choices[0].text),
map(data => data.choices[0].text)
import { Injectable } from '@angular/core';
import { Configuration, OpenAIApi } from 'openai';
import { environment } from '../environments/environment';
@Injectable({
providedIn: 'root'
})
export class OpenAiService {
constructor() { }